- Home /
Question by
PhysicalBeef · Dec 05, 2015 at 06:08 PM ·
rotationjavascriptrigidbodytransformvector2
Rotating Rigidbody properly using AddRelativeForce
horizontalMovement = Vector2(rb.velocity.x, rb.velocity.z);
if(horizontalMovement.magnitude > totalSpeed) {
horizontalMovement = horizontalMovement.normalized;
horizontalMovement *= totalSpeed;
}
rb.velocity.x = horizontalMovement.x;
rb.velocity.z = horizontalMovement.y;
That's my script for stopping smoothly and not floating away.
transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(mouseMovement).currentYRotation, 0);
rb.AddRelativeForce(PlayerPrefs.GetInt("directionSide"), 0, PlayerPrefs.GetInt("directionForward"));
I'm using PlayerPrefs to store data, since its a bit easier. (it works, that's not the problem!) Also, script above contains both movement AND rotation. With this rotation when i hold W and turn left, the turn takes wayyy longer than it should, and is really slow and unbareable. How to make the rigidbody's speedy slowly thing(the slow turning) move with my transform.rotation?
Other Info:
directionSide is left-right (called by A and D keys)
directionForward is forward-back (called by W and S keys)
rb is rigidbody
Comment