- Home /
Adding force relative to player's rotation with rigidbody.velocity
Hey there !
I'm currently creating a character controller and I'm trying to make it so the player can do a full loop. I have ground alignment set up and working, but the force isn't being added relative to the player's rotation.
Here's a snippet of the code i'm using to add force.
void AddForce(Vector3 direction, float force)
{
rigidbody.velocity = (direction * force) + rigidbody.velocity
}
// Direction is the direction that the force is being added to (ex. direction of the joystick)
// Force is the amount of force being added
How can i make it so it adds force to the player relative to his rotation, with rigidbody.velocity ?
Answer by RadonRaph · Oct 10, 2019 at 03:50 PM
Hello, Your function AddForce already exist in Rigidbody and you have the AddForceAtPosition that take count of rotation :) Read more at https://docs.unity3d.com/ScriptReference/Rigidbody.html Hope that help ! Raph
Good answer, but sadly not the solution i'm looking for. I'm trying to make the character movement have maximal precision, while still having some momentum. That's why 'm using rigidbody.velocity ins$$anonymous$$d of Rigidbody.AddForce (or simmiliar pre-built functions). The pre-built AddForce function just ruins precision.