- Home /
Character moves off to side and floats
Hello again. I have used a script that has been very successful. Thanks to alucardj I now have a script that makes the character play the animations and move. Yet whenever I try to make the character move forward (by pressing the 'w' key) it moves off to the side and floats above the ground! Here is my script:
#pragma strict
var leftButton : String;
var rightButton : String;
var forward : Vector3;
var dt : float; // double;
var leftRotation : float;
var rightRotation : float;
var suspended : boolean;
var moveSpeed : float; // double;
function Start()
{
leftButton = "w";
rightButton = "s";
forward = Vector3.forward; // new Vector3( 0, 0, 1 );
dt = Time.deltaTime;
leftRotation = -0.7071069;
rightRotation = 0.7071069;
suspended = false;
moveSpeed = 3.0;
}
function Update()
{
if ( suspended )
{
return;
}
//if (Input.GetButton(leftButton))
else if ( Input.GetKey( leftButton ) )
{
transform.Translate( forward * moveSpeed * dt );
animation.Play( "Walk_" );
}
//else if (Input.GetButton(rightButton))
else if ( Input.GetKey( rightButton ) )
{
transform.Translate( forward * moveSpeed * dt );
animation.Play( "Walk_" );
}
else
{
animation.Play( "Rest" );
}
}
function SetSuspension( setting : boolean )
{
suspended = setting;
}
Is there anything wrong with this script? I edited it a little and made it a little better, but nothing seems to be wrong except the fact that the character moves to the side and floats.
FIXED! my actual animated character was moved off to the side and floating above the ground! $$anonymous$$ake sure that when you animate your character, it is in the same spot each time.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
What dimensions for a GUI texture 2D main menu? 1 Answer
Unity Script Refernece 1 Answer