Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by $$anonymous$$ · Apr 18, 2016 at 01:28 PM · c#animationcharactercontroller

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges