- Home /
Having trouble having a player run and shoot at the same time....
Would really like to figure out how to get a player to either run and attack at the same time, OR less ideal stop their forward movement while the attack animation is playing. Right now when I press E (attack) and still am moving forward the characters run animation stops playing.
I tried checking out Unity's AnimationMix documentation HERE
But couldn't figure out how to assign the shoulder, joints etc...
Here's my code that I am working with:
function Start () {
// Set all animations to loop animation.wrapMode = WrapMode.Loop; // except shooting animation["jump"].wrapMode = WrapMode.Once; animation["attack1"].wrapMode = WrapMode.Once;
// Put idle and walk into lower layers (The default layer is always 0) // This will do two things // - Since shoot and idle/walk are in different layers they will not affect // each other's playback when calling CrossFade. // - Since shoot is in a higher layer, the animation will replace idle/walk // animations when faded in. animation["jump"].layer = 1; animation["attack1"].layer = 1;
// Stop animations that are already playing //(In case user forgot to disable play automatically) animation.Stop(); }
function Update () { // Based on the key that is pressed, // play the walk animation or the idle animation if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2) animation.CrossFade("run"); else animation.CrossFade("idle");
// jump if (Input.GetKeyDown(KeyCode.Space)) animation.CrossFade("jump");
// Attack if (Input.GetKeyDown(KeyCode.E)) animation.CrossFade("attack1");
// Move Left if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2) animation.CrossFade("run");
}
Any help would be GREATLY appreciated :)
Your answer
Follow this Question
Related Questions
Blended Animation offsetting 0 Answers
Animation Blending Issue 2 Answers
Getting weird behaviour when blending animations of behaviour fields 1 Answer
Sharing animations between models 2 Answers
Character animation problem 1 Answer