Pawn accelerate and brake to location

Hi!

I haven’t been able to find similar questions and/or solutions regarding this so here it is: I need to make a pawn move from point A to point B accelerating and then braking (decelerating) to get to the target location.

I’m currently using Pawn Movement and Add Movement Input, so I get the target location, calculate the distance and direction to that location and then adding movement input using the Vector Unit Direction.

This works, but obviously, the pawn overshoots the target location and then bounces back and so on.

I know this can be solved with math (I’m really bad at it) or maybe my implementation is completely wrong. Can you please help me before making a bigger mess?

Thanks!

Finally fixed it by:

BrakeDistance = (Velocity.Length^2 / (Acceleration * 2)) + ((Velocity.Length) * DeltaSeconds).

These are some important things to consider:

  1. When the distance to target is greater than the brake distance then add input with a scale of 1.0 towards target location.
  2. When the distance to target is less than the brake distance then add input with a scale -0.1 (or something that works for you) towards target location.
  3. When the distance to target is less than a safe length (e.g: 500 * DeltaTime or something like that) then just interpolate the movement towards the target location.
  4. When the distance is within an acceptable value (e.g.: 50), then do nothing.

Point 4 is the most relevant since if you do not consider this, then unexpected accelerations will occur once the actor is close to the target point.

A somewhat explanatory Blueprint is located here: UpdateMovement posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4