You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New expressions: "Object.VectorX(angle, distance)" and "Object.VectorY(angle, distance)" #2304
A gamedev knows a vector (angle and distance) and they want to know the endpoint position of the vector. This will be useful for any function that requires a position as input, such as position Tween and Pathfinding. This will make it easy to use tweens for knockback or dashes in any direction.
Solution suggested
Create two new expressions:
Object.VectorX(angle, distance) = Given an angle and distance, return the X position of the resulting vector.
Object.VectorY(angle, distance) = Given an angle and distance, return the Y position of the resulting vector.
This can be calculated using trigonometry functions:
This would be surely interesting. Note that we have the reverse already:
For objects:
get the angle: Object.AngleToObject, Object.AngleToPosition
get the distance: Object.Distance (should have been called DistanceToObject... no big deal), Object.DistanceToPosition (and the squared equivalent: SqDistance, SqDistanceToPosition).
Expressions:
angle: AngleBetweenPositions
distance: DistanceBetweenPositions
Note that to be useful in most cases, the Angle and Distance for objects are from the object center.
So what you're suggesting is to offer the reverse operation.
I'm not sure about two things.
The naming. Basically, we translate from "polar coordinates" to "cartesian coordinates". In GDevelop, we don't talk about cartesian coordinates but just about "X/Y" and we don't tell usually "Polar" coordinates, but just "Distance and angle to somewhere/something". So should we should call this:
VectorX/Y
PolarVectorX/Y
something else? DistanceAndLengthX/Y?
The Object.VectorX/Y should be, to be consistent with what's existing, calculated from the object center.
If we're looking to keep the same naming structure, I'd think "PositionByAngleAndDistance", "Object.PositionByDistanceAndAngle" are both accurate but also relatively long.
Yes that would work even if a bit verbose PositionXByDistanceAndAngle/PositionYByDistanceAndAngle .
Could also by without abbreviation: XByDistanceAndAngle/YByDistanceAndAngle but maybe too implicit now..
Activity
4ian commentedon Feb 12, 2021
This would be surely interesting. Note that we have the reverse already:
Object.AngleToObject,Object.AngleToPositionObject.Distance(should have been calledDistanceToObject... no big deal),Object.DistanceToPosition(and the squared equivalent:SqDistance,SqDistanceToPosition).AngleBetweenPositionsDistanceBetweenPositionsNote that to be useful in most cases, the Angle and Distance for objects are from the object center.
So what you're suggesting is to offer the reverse operation.
I'm not sure about two things.
VectorX/YPolarVectorX/YDistanceAndLengthX/Y?Silver-Streak commentedon Feb 12, 2021
If we're looking to keep the same naming structure, I'd think "PositionByAngleAndDistance", "Object.PositionByDistanceAndAngle" are both accurate but also relatively long.
4ian commentedon Feb 14, 2021
Yes that would work even if a bit verbose
PositionXByDistanceAndAngle/PositionYByDistanceAndAngle.Could also by without abbreviation:
XByDistanceAndAngle/YByDistanceAndAnglebut maybe too implicit now..