- Home /
Question by
Pawlik · Aug 20, 2012 at 11:54 AM ·
animation2dcharacter controller2d animation
2d and character controler
I have a problem with 2d toolkit and character controller, it does not start the if statement that supposed to play walk animation (it it stuck in the idle). can someone point out what am I missing?
[...]
function Update ()
{
var anim : tk2dAnimatedSprite;
anim = GetComponent(tk2dAnimatedSprite);
var controller : CharacterController = GetComponent ( CharacterController ); // set controller to character controller
if( controller.isGrounded ) //if character on ground
{
velocity = Vector3 ( Input.GetAxis("Horizontal"), 0, 0 );
if ( velocity.x == 0 ) //idle
{
if (anim.isPlaying() && anim.CurrentClip.name != "idle")
{
anim.Play("idle");
}
}
if ( velocity.x < 0 ) //walk left
{
velocity *= walkSpeed; //move left based on the walkspeed
if (anim.isPlaying() && anim.CurrentClip.name != "walk")
{
anim.Play("walk");
print ("walk_left");
}
}
if( velocity.x > 0 ) //walk right
{
velocity *=walkSpeed; //move right based on the walkspeed
if (anim.isPlaying() && anim.CurrentClip.name != "walk")
{
anim.Play("walk");
print ("walk_right");
}
}
[...]
Comment
Your answer
Follow this Question
Related Questions
Sprite Rect Moves Between Frames 0 Answers
Localscale-flipped 2D character retains original rotation since 5.4 2 Answers
2D Animation does not start 1 Answer
Need help on skeletal Animation 0 Answers