How can I add Relative Force?

Hi, I’m trying to add force to my ship, but it’s using world space. I don’t have an option like AddRelative force, in C++, how do I go about adding force in the ship’s forward vector?

You will need to create the force vector in world space from the rotation of your ship.

E.g.

const FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);

Then, depending on what movement mechanics you are using you can use this direction in e.g. AddMovementInput(Direction, magnitude).

My RootComponent is a StaticMeshComponent with SetSimulate physics true, gravity disabled. Yesterday I tried out FVector Fwd; MeshComp->GetForwardVector(), then MeshComp->AddForce(Fwd), or something like that lol. It seemed to add force in the right direction while throttling, but then had some issues, I’ll try what you’ve suggested and get back with you :smiley:

This doesn’t seem to work with AddForce. I have to use physics, because if I use translations like AddLocalOffset or anything, since I’m not using gravity if I hit something, I go into a spin I can’t get out of because I can’t add forces and torque correctly :frowning: