Hello!
I have this script that is supposed to turn the player smoothly on the direction that he walks. But the problem is that it turns immediatly, like the electrons of CERN!!! What’s wrong?
#pragma strict
var speed : float = 0.7;
var playergraphic : GameObject;
var RotSpeed : float;
private var newRot = Quaternion.Euler(0,90,0);
function Start () {
}
function Update () {
var CurrentSpeed = Input.GetAxis("Horizontal") * speed;
rigidbody.velocity = Vector3(CurrentSpeed,0,0);
playergraphic.transform.rotation = Quaternion.Slerp(transform.rotation, newRot, Time.time * RotSpeed);
if(rigidbody.velocity.x > 0)
{
newRot = Quaternion.Euler(0,90,0);
playergraphic.animation.CrossFade("Walk");
}
else if(rigidbody.velocity.x < 0)
{
newRot = Quaternion.Euler(0,270,0);
playergraphic.animation.CrossFade("Walk");
}
else {
playergraphic.animation.CrossFade("Idle");
}
}
The player has the main capsule collider as a parent object, and the graphicks are on a child object, that I want t turn. This is attached to the variable “playergraphic”