- Home /
Rotating Character
I am using unitys movement script
void Update() {
CharacterController controller = GetComponent<CharacterController>();
if (controller.isGrounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= runningSpeed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= Gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
In the input tags i changed horizontal to me controlled with Q and E because i want A and D to rotate the character. What would i do to do this. Would it me another moveDirection or what?
Answer by aldonaletto · Jun 13, 2011 at 12:38 PM
Add this line at the beggining of the Update function:
void Update(){
transform.Rotate(0,Input.GetAxis("Rotate")*60*Time.deltaTime,0);
CharacterController controller = ...
You must also define the "Rotate" axis in the input manager and assign the keys "a" and "d" to the Positive and Negative buttons. The value 60 above indicates it will turn 60 degrees per second in each direction - change it if the turning speed is too high or too low.
$$anonymous$$aybe you should write 60f as the turning speed - C# is fussy about float constants without this f.
woooooh, you just solve my problem which i've been battling for days. Thanks bro, keep it up!!!!