- Home /
Animations not playing when holding W + A
I'm using a custom character controller in Unity 5 rather than the standard one. I have my first person character, that has first person legs, and arms, and they have animations attached to them. In my character script, I have it to play animations when the character moves. W plays the walkforward animation on the legs, and the walking animation on the arms. A plays the walkleft animation on the legs, and the same walking anim on the arms, and vice versa for S and D. The animations play fine when you're only pressing one at a time. My problem is, when I press W + A, or W + D together, the animations don't play, and that stuff. The walk left animation starts to play, but doesn't loop, and just stops. Same goes for my arms, and footsteps, none seem to play when pressing 2 keys at once. Strangely enough, when holding shift to sprint, it all works just fine.
Here's a gif when the character walks forward, notice the legs (for a quick second), and the animation playing when the gun is aiming. That's the second walking animation, specifically for when aiming only. http://i.imgur.com/6HlWDxx.gifv
Now take a look at it when you're walking forward and left, holding W + A. The walkleft animation starts on the legs, but then stops, and stays like that, footstep sounds stop playing, and the aiming walk animation doesn't change, it stays to the normal walking animation (not aiming animation) http://i.imgur.com/liNsYwu.gifv
Here is my code for the animation stuff
void Animations()
{
Animation legsAnim = characterLegsTransform.GetComponent<Animation>() as Animation;
Animation charAnim = weaponAnimationHolder.GetComponent<Animation>() as Animation;
Rigidbody rigidbody = character.GetComponent<Rigidbody>() as Rigidbody;
if (rigidbody.velocity.magnitude < 1) {
legsAnim.CrossFade("idle");
if (!isAiming) {
charAnim.CrossFade("Idle");
} else {
charAnim.CrossFade("Idle2");
}
}
if (!isAiming && IsGrounded()) {
if (rigidbody.velocity.magnitude > 7 && Input.GetKey(KeyCode.LeftShift)) {
if (character.GetComponent<WeaponController>().CurrentWeapon.firemode == "semi"){
charAnim.CrossFade("Running");
}else{
charAnim.CrossFade("Running");
}if (Input.GetKey(KeyCode.W)) {
legsAnim["walkforward"].speed = 2.6f;
legsAnim.CrossFade("walkforward");
}if (Input.GetKey(KeyCode.A)) {
legsAnim["walkleft"].speed = 2.6f;
legsAnim.CrossFade("walkleft");
}if (Input.GetKey(KeyCode.D)) {
legsAnim["walkright"].speed = 2.6f;
legsAnim.CrossFade("walkright");
}if (Input.GetKey(KeyCode.S)) {
legsAnim["walkbackward"].speed = 2.6f;
legsAnim.CrossFade("walkbackward");
}}}
if (!isAiming && IsGrounded()) {
if (rigidbody.velocity.magnitude > 1 && rigidbody.velocity.magnitude < 5) {
charAnim.CrossFade("Walking");
if (Input.GetKey(KeyCode.W)) {
legsAnim["walkforward"].speed = 1.3f;
legsAnim.CrossFade("walkforward");
}if (Input.GetKey(KeyCode.A)) {
legsAnim["walkleft"].speed = 1.3f;
legsAnim.CrossFade("walkleft");
}if (Input.GetKey(KeyCode.D)) {
legsAnim["walkright"].speed = 1.3f;
legsAnim.CrossFade("walkright");
}if (Input.GetKey(KeyCode.S)) {
legsAnim["walkbackward"].speed = 1.3f;
legsAnim.CrossFade("walkbackward");
}}}
if (isAiming && IsGrounded()) {
if (rigidbody.velocity.magnitude > 1 && rigidbody.velocity.magnitude < 5) {
if (isAiming){
charAnim.CrossFade("Walking2");
}}}
}
public bool IsGrounded() {
return Physics.Raycast(transform.position, -Vector3.up, distanceToGround + 0.3f);
}
Here's for the footsteps
void Footsteps()
{
if (IsGrounded() && character.GetComponent<Rigidbody>().velocity.magnitude > 1 && character.GetComponent<Rigidbody>().velocity.magnitude < 5 && !isBusy)
{
StartCoroutine(FootstepInterval(footsteps_grass, stepIntervalWalking));
}
if (IsGrounded() && character.GetComponent<Rigidbody>().velocity.magnitude > 7 && !isBusy)
{
StartCoroutine(FootstepInterval(footsteps_grass, stepIntervalRunning));
}
}
IEnumerator FootstepInterval(AudioClip[] aclip, float time)
{
audio.clip = aclip[Random.Range(0, aclip.Length)];
audio.pitch = Random.Range(.8f, 1f);
audio.Play();
isBusy = true;
yield return new WaitForSeconds(time);
isBusy = false;
}
Anyone know what's causing this and how to fix it? Thanks!
Your answer
Follow this Question
Related Questions
Simple c# Character Controller + Animations / Side-scroller 0 Answers
Idle Animation fighting/overriding other ground animations 0 Answers
lip movement / animation in unity 0 Answers
How to trigger different animations depending on where a gameobject collides? 1 Answer
Multiple Cars not working 1 Answer