Skip to content

New expressions: "Object.VectorX(angle, distance)" and "Object.VectorY(angle, distance)" #2304

Closed

Description

@tristanbob

Description

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:

Object.VectorX(angle, distance) = return Object.X() + (distance * cos(ToRad(angle)))
Object.VectorY(angle, distance) = return Object.Y() + (distance * sin(ToRad(angle)))

Activity

  1. 4ian commented on Feb 12, 2021

    @4ian
    Owner

    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.

    1. 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?
    1. The Object.VectorX/Y should be, to be consistent with what's existing, calculated from the object center.
  2. Silver-Streak commented on Feb 12, 2021

    @Silver-Streak
    Collaborator

    If we're looking to keep the same naming structure, I'd think "PositionByAngleAndDistance", "Object.PositionByDistanceAndAngle" are both accurate but also relatively long.

  3. 4ian commented on Feb 14, 2021

    @4ian
    Owner

    Yes that would work even if a bit verbose PositionXByDistanceAndAngle/PositionYByDistanceAndAngle .
    Could also by without abbreviation: XByDistanceAndAngle/YByDistanceAndAngle but maybe too implicit now..

  4. Repository owner locked and limited conversation to collaborators on Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions