Hi, Im using the Unity Stealth game tutorial movement system for my own game, for some reason when I first launch the game on the editor it gives me this error and the character starts walking forward, if I stop it and launch it again the error is gone and everything works perfectly, here’s the code related to character movement:
function MovementManagement (horizontal : float, vertical : float)
{
// If there is some axis input...
if(horizontal != 0f || vertical != 0f)
{
// ... set the players rotation and set the speed parameter to 1.7f.
Rotating(horizontal, vertical);
anim.SetFloat(hash.speedFloat, 1.7f, speedDampTime, Time.deltaTime);
}
else
// Otherwise set the speed parameter to 0.
anim.SetFloat(hash.speedFloat, 0);
}
function Rotating (horizontal : float, vertical : float)
{
// Player can only be rotate while he's alive
if (health >= 1)
{
// Create a new vector of the horizontal and vertical inputs.
var targetDirection : Vector3 = new Vector3(horizontal, 0f, 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 * Time.deltaTime);
// Change the players rotation to this new rotation.
rigidbody.MoveRotation(newRotation);
}
}
The line actually giving me the error is this one:
// Create a rotation based on this new vector assuming that up is the global y axis.
var targetRotation : Quaternion = Quaternion.LookRotation(targetDirection, Vector3.up);
Im kind of a noob, here, any ideas what’s causing it?