- Home /
Question by
BubblesTheDude · Jan 08, 2020 at 07:57 PM ·
vector3velocitylocalrotation
how do i make rigidbody. velocity follow the objects local rotation?
I'm making a movement script with velocity so I can use physics for other movement things.
I was wondering if there was a way to make the vector 3 follow the local rotation of the player
current code: inputVector = new Vector3(Input.GetAxisRaw("Horizontal") * movSpeed, playerBody.velocity.y, Input.GetAxisRaw("Vertical") * movSpeed); playerBody.velocity = inputVector;
Comment
Best Answer
Answer by Bunny83 · Jan 08, 2020 at 08:06 PM
Something like that:
inputVector = playerBody.transform.InverseTransformDirection(playerBody.velocity);
inputVector.x = Input.GetAxisRaw("Horizontal") * movSpeed;
inputVector.z = Input.GetAxisRaw("Vertical") * movSpeed;
playerBody.velocity = playerBody.transform.TransformDirection(inputVector);
Thank you so much. you just saved me so much time!