How do i add a force to my pawn, in the direction it is pointing?

I’m currently building a spaceflight game and i wanted to have movement that preserves the momentum of the ship when no input is received. in a way that when you move the ship, it keeps moving until it is acted upon, due to the vacuum of space. So I’ve been trying to move my pawn with AddForce, but it only adds force relative to the world space, and not the pawn. how can I get the force to be added in the direction that I want the ship to move, relative to the ships orientation? I tried getting a direction vector by having a second static mesh in front of the ship, and using GetUnitDirection to use for my force vector, but that didn’t seem to work.

1 Like

Hello! You can use this SomeSceneComponent->GetComponentTransform().GetUnitAxis(EAxis::X) to get forward vector for some USceneComponent in World space. Just use it with primary mesh component.

hmm im not sure how to do that with the blueprints. the only function i can see that resembles that is GetActorTransform. but that seems to not be entirely dependable, as it seems to be misaligned with the mesh’s orientation.

You need to choose something on your pawn / character that is facing the way you want and use that vector to make the force / movement. For a character it might be

For a pawn, going in the camera direction

345333-screenshot-2.jpg

Or perhaps for your ship, to preserve the current momentum:

Etc

1 Like