add characterstates to third person controller ?

Hi everybody, my name is Nico and i’m new to Unity, i’ve been “working” with it for two months now nut i still have some problems.

I’m trying to add more _characterStates to the Third Person Controller script provided with Unity. I’ve been trying lots of thing, none worked.

So I used a custom function triggered by keydown:

if (Input.GetKeyDown(KeyCode.LeftAlt))
{
   Throw();
   GameManager.canTake = false;
   Debug.Log("throw");
   isIdle = false;
}

and here’s the function:

function Throw() 
{ 
   _animation.Play(ThrowAnimation.name); 
}

the animation plays but only for a frame or two and then returns to idle mode. More than that, I’m just asking myself if there would be a conflict between the function and characterstate.

I really think it’s gotta be a problem with CharacaterState but I can’t find it.

Would someone have any idea on how to add characetrestates or making the animation run till it’s end?

Thanks in advance. Nico

Good question. I’m a huge fan of player states and usually set up enumerators to help with this… that’s way off topic but look into enum when you get a chance.

Use a loop like this to control your animation, especially if you want it to play the whole animation:

`
if(animation.IsPlaying(ThrowAnimation.name))
{

}	
`

Seems like you got a good grasp of what needs to be done, just play with the .IsPlaying method of the animation class.

I used this snippet to work through a player death state for a tutorial:

`

	if (playerState == DEAD)//Dead set when you are hit by a bullet
		{
			
		// use this for death.
			if (!deathStarted)
			{
			animation.Play("death");
			deathStarted = true;
			}
			if(!animation.IsPlaying("death"))//note the ! in there
			{
			playerState = RESPAWN;
			cController.transform.Translate(0, transform.position.y +20.0f, 0);
			deathStarted = false;
			}	
		}
	}

`

I hope that is enough to get you in the right direction. Comment if you need some more help and welcome to the forums!