I’m trying to rotate my gameobject when I press a key, similar to what happens when you move. I’m using this script to move and would like to be able to rotate to simulate movement by rotating.
Any help would be greatly appriciated by me and my bloodshot eyes
function Update () {
rigidbody.AddForce(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
}
You can rotate your game object’s transform using Transform.Rotate
When working with a rigidbody you should use FixedUpdate
Something like this:
function Update () {
transform.Rotate(0.0, Input.GetAxis("Horizontal"), 0.0);
}
function FixedUpdate () {
rigidbody.AddForce(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
}
That’s a simple example of how you might want to go about it. Perhaps you want to adjust the actual rate of rotation, but I’ll leave that as an exercise for you.