- Home /
Question by
kirax105strike · Jan 26, 2014 at 07:35 AM ·
movementtopdown
Add a slight rotation when moving horizontal
I have a movement script that I am using in a topdown style game. Currently I have the movements all working correctly except I am trying to add a slight rotation to my player object when moving in the horizontal direction. Here is what I have for the x,z movement:
var x = Input.GetAxis("Horizontal") * Time.deltaTime;
var z = Input.GetAxis("Vertical") * Time.deltaTime;
var rotation = Input.GetAxis("Rotate") * Time.deltaTime;
transform.Translate(x,0.0f,z);
transform.Rotate(0.0f, rotation, 0.0f);
I also have a "Rotate" movement that rotates my object around the y-axis which could be why adding another rotation keeps messing up. Any ideas on how to add the slight rotation on horizontal movement?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613131455im_/https://answers.unity.com/themes/thub/images/avi.jpg)