Animation and movement dependant on direction

Yeah, I’m abuzz with a lot of scripting stuff aren’t I? (Never was too good at script) Anyways, this should be a quicky, I need my scripts to figure out which direction I’m telling my character to go in so that I can give hm different animations and different speeds. Obviously we can’t run at full speed when walking sideways, and I really don’t want my character to run as fast backwards as it can forwards.

What I have are four animations, Run, WalkBack, Strafe-Left, and Strafe-Right. If I’m going straight to the left I want my strafe-left animation to play, and so on and so forth (kind of obvious what animations I want to play when). I originally have “if (Mathf.Abs(Input.GetAxis(“Vertical”)) > 0.2) animation.CrossFade(“run”);” this gives my character a ‘lurch’ into the run animation, and not just going off if I tap the forward button, but it doesn’t determine whether I have forward or backwards down, as it plays the run animation whether I’m going backwards or forwards.

The same problem exists in determining the speeds. even if I have it check if my direction is negative (if vertical is < 0) it still runs at full speed, with this being said the same -WILL- happen if I start playing with my horizontal axises, as it will always see the movement in a positive direction (kind of awkward, but it will).

Anyone know of a way for my scripts to “see” which direction I’m going in and play the correct animations and speeds?

EDIT:

Nevermind, I found a solution, it’s a little messy, but it works. I just created duplicate buttons of the four directions and whenever I have those certain buttons down it’ll play those animations.

Have you tired replacing “Vertical” with “Horizontal”? I’m not sure how your controls are set up, but it could either send you walking in the direction you want, or turn you in place in that direction.

I am working on something similar for NPC characters, and am having issues getting them to play animations. Have you hand any luck with that?

NPC animations I haven’t touched on yet, as most of my NPCs in my game are enemies (I plan on a couple of friendly ones later). But as I said, I got everything sorted out. “Vertical” for controls means your forward and backward movements (not up and down), but because there was no way to tell the script which button I was pressing (positive or negative), I just told my script that if I was holding down the forward button, play the run animation and same with everything else.

Again, it’s a little messy, but the four extra controls just tell my scripts what buttons I’m pressing, while my get-axis buttons remain the same.

To NPC Animations, I can get them to play “idle” animations. that’s as far as I’ve got for NPC animations. I can also get them to do “talking” animations, but that doesn’t require any movement. The only thing I can suggest is looking at the Lerpz tutorial for enemy/NPC animations, because I don’t know that yet ^^;;

Cool, glad to hear that the problem is solved. By NPC, I was also meaning Enemy, should have been more specific. I’m able to get Enemies either to play an Idle or a walk but am have trouble getting them to do both.