Skip to main content
Drnichol
Participant
July 16, 2026
Question

How do I calculate projectile motion between two coordinates?

  • July 16, 2026
  • 1 reply
  • 9 views

I'm working on a simple projectile motion system and I'm trying to calculate the trajectory between two points.

I know the starting position (x1, y1) and the target position (x2, y2), but I don't know the launch angle or the initial velocity. The start and target positions can change every time, so I can't use fixed values.

What is the best mathematical approach or algorithm to calculate the correct launch angle and speed so the projectile reaches the target accurately? If there are multiple solutions or common methods, I'd appreciate an explanation or an example.

Thank you!

    1 reply

    ShiveringCactus
    Community Expert
    Community Expert
    July 16, 2026

    Decades ago, someone made a tank game in After Effects.  I’ve been trying to find it.   

    But in the meantime, I think this expression should work:

    // 1. Reference layers
    targetLayer = thisComp.layer("Target NULL");
    targetPos = targetLayer.transform.position;

    // Use 'valueAtTime' on the layer's static/keyframes position at the In Point
    startPos = position.valueAtTime(inPoint);

    // 2. Define duration and map "time" to a progress variable "t" (0 to 1)
    duration = 1; // Flight duration in seconds
    t = clamp((time - inPoint) / duration, 0, 1);

    // 3. Linear interpolation using our normalized 't'
    linearX = ease(t, 0, 1, startPos[0], targetPos[0]);
    linearY = ease(t, 0, 1, startPos[1], targetPos[1]);

    // 4. Calculate the arc height (parabola) using 't'
    arcHeight = 300;
    parabola = 4 * t * (1 - t) * -1 * arcHeight;

    // 5. Combine linear path with the vertical arc offset
    [linearX, linearY + parabola]

    It’s not perfect, but might be a starting point to adapt

    ShiveringCactus
    Community Expert
    Community Expert
    July 16, 2026

    @Nishu Kushwaha - just noticed the Code layout that matches AE’s.  Nice.