I have used the same model as they said in the Tutorial but when I got left he goes right and when I go right he goes left.
Anyone know the solution?
#pragma strict
public var turnSmoothing : float = 15f; // A smoothing value for turning the player.
public var speedDampTime : float = 0.1f; // The damping for the speed parameter
public var smoothTurn : float = 0.2f;
private var anim : Animator; // Reference to the animator component.
function Awake ()
{
// Setting up the references.
anim = GetComponent(Animator);
}
function FixedUpdate ()
{
// Cache the inputs.
var h : float = Input.GetAxis("Horizontal");
var v : float = Input.GetAxis("Vertical");
var sneak : boolean = Input.GetButtonDown("Sneak");
MovementManagement(h, v, sneak);
}
function Update ()
{
}
function MovementManagement (horizontal : float, vertical : float, sneaking : boolean)
{
if(horizontal != 0f || vertical != 0f)
{
// ... set the players rotation and set the speed parameter to 5.5f.
Rotating(horizontal, vertical);
anim.SetFloat("Speed", 5.5f, speedDampTime, smoothTurn);
}
else
// Otherwise set the speed parameter to 0.
anim.SetFloat("Speed", 0);
}
function Rotating (horizontal : float, vertical : float)
{
// Create a new vector of the horizontal and vertical inputs.
var targetDirection : Vector3 = new Vector3(0f,horizontal,vertical);
// Create a rotation based on this new vector assuming that up is the global y axis.
var targetRotation : Quaternion = Quaternion.LookRotation(targetDirection, Vector3.up);
// Create a rotation that is an increment closer to the target rotation from the player's rotation.
var newRotation : Quaternion = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * smoothTurn);
// Change the players rotation to this new rotation.
rigidbody.MoveRotation(newRotation);
}