Add Velocity Directly to FloatingPawnMovement

I am using a FloatingPawnMovement component to move my player. It works great. I’m implementing a “dash” function. This function uses a UCurveFloat to control the dash’s movement speed in a straight line. I update the position of the pawn using:

SetActorLocation(GetActorLocation() + DashDirection * DashTransition.GetValueDelta(), true, HitResult, ETeleportType::None);

The DashTransition struct just gives me the exact distance I need to move based on delta time. This all works great, but the problem is the pawn comes to a sudden stop when the dash ability ends.

I’ve tried tracking the frame velocity and setting the movement component’s Velocity directly when the dash ends. Also tried AddInputVector using the frame’s velocity, and using different ETeleportTypes, but the pawn always comes to an abrupt stop.

I was hoping to have a way to trick the movement component into treating an incoming velocity value the same way it does regular movement, where if I let go of the movement key it drifts to a stop.

Is there a way to do this?

1 Like

Ok so the first mistake I made above was setting the Velocity much too low to see anything. I updated it to:

MovementComponent->Velocity = (GetActorLocation() - LastActorLocation) / DeltaTime;

This time I got “drift”, but the Pawn doesn’t stop moving at all, it just slides quickly to the other side of the map. I tried scaling that value and I get a kind of drifty like effect, but with strange stutters. I’m guessing setting Velocity directly is just bad?

It was all user error. Setting the Velocity directly on the FloatingPawnMovement component works, I just had a much too low Velocity initially, and then when I fixed that, too low a Deceleration value to compensate for the extreme velocity of the dash.

2 Likes