- Home /
Turning character with transform.Rotate
I'm having some difficult in trying to turn my character with transform.Rotate (at least I believe that's the problem). I've gotten it to work for the most part, but whenever I turn my character without already moving forward, and I then want to try moving my character forwards, the camera and model don't align with the direction the character is going forward. I'm not amazing with Javascript yet, but any tips/feedback would be awesome.
Also, on a side note - what is the best object to put this script on so that my object (with rigidbody) doesn't fall over when hitting other objects?
Here's what I have so far:
//Moving left/right if (horMovement) { transform.Translate(transform.right * horMovement * Time.deltaTime * speed); } //Moving forwards/backwards if (forwardMovement) { transform.Translate(transform.forward * forwardMovement * Time.deltaTime * speed); } //Turning left/right if (turnMovement) { transform.Rotate(0, turnMovement*Time.deltaTime*speed *turnSpeed, 0,Space.World); } }
Comment
You shouldn't be using transform.anything if your model uses a non-kinematic rigidbody. Use AddForce and AddTorque ins$$anonymous$$d.