Question by
NoScopeGG · Oct 28, 2017 at 04:40 PM ·
c#rotationmovement script
Cube turns in moving direction, but always returns to default direction
So I got my cube to move and turn in the direction it is going, but when I stop moving it, it turns to the front again (z axis I believe). I know about Space.World, but I dont know where or how to fit it in my code:
public float speed = 18;
public float sprint = 30;
private Rigidbody rig;
void Start ()
{
rig = GetComponent<Rigidbody>();
}
void Update ()
{
float hAxis = Input.GetAxis("Horizontal");
float vAxis = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(hAxis, 0, vAxis) * speed * Time.deltaTime;
rig.MovePosition(transform.position + movement);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.15F);
gameObject.GetComponent<Renderer>().material.color = Color.red;
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612142033im_/https://answers.unity.com/themes/thub/images/avi.jpg)