- Home /
Unity Move Script How to add rotation?
I want to add rotation to the unity move script available on the scripting reference but i honestly dont know how. I set up a project tag called rotate i just dont understand how to make it.
Just so you guys dont have to go on the scripting reference here is the script for it using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed = 6.0F;
public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent<CharacterController>();
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}
minus the if statement telling if the player is on the ground. The game im working on has to deal with flight and this works out pretty well.
Thanks in advanced, zeneth77
Answer by farooqaaa · Mar 23, 2012 at 02:01 AM
You can use transform.Rotate() to rotate.
public float rotateSpeed = 10f;
public Update()
{
// rotate around y-axis
transform.Rotate(0, rotateSpeed * Time.deltaTime;
}
Some formatting errors. Should be:
public float rotateSpeed = 10f;
public Update()
{
// rotate around y-axis
transform.Rotate(0, rotateSpeed * Time.deltaTime, 0);
}
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Flip over an object (smooth transition) 3 Answers
Rotating Character 1 Answer
Orbit Camera Around Player And Add Force 3 Answers
Rotate towards movement direction 1 Answer