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 /
This question was closed Apr 18, 2018 at 04:37 PM by Fibonacci_0_1_1 for the following reason:

Changed the script completely. No longer require an answer.

avatar image
0
Question by Fibonacci_0_1_1 · Apr 18, 2018 at 03:27 AM · animationtriggercharacter movementanimation controlleranimation script

Idle Animation Won't Play

I have a unity script which controls my animations and sets triggers to play each of those animations. The triggers are called using W, A, S or D and each of those play animations of jogging forward/back and strafe left/right. When W, A, S and D (all four of these keys) are up, i call my idle animation but it doesn't play. When the game starts, my player is in idle state, but when i press any of the four keys (W, A, S or D) the state of that key plays forever even once GetKeyUp is true. I'm assuming something is wrong with my conditions for the idle state as it never becomes true, I'm just curious as to why so i can fix it. I've tried many different arrangements of the code and the the animator transitions just in case but nothing seems to work.

I'm trying to have it so that is all keys (W, A, S and D) are up, then idle animation will play.

Here is the animation script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class player_animation_control : MonoBehaviour {
 
     Animator animationComponent;
     
     int jogHashId = Animator.StringToHash("Jog");
     int jogBackwardsHashId = Animator.StringToHash("JogBackwards");
     int strafeLeftHashId = Animator.StringToHash("StrafeLeft");
     int strafeRightHashId = Animator.StringToHash("StrafeRight");
     
     int idleHashId = Animator.StringToHash("Idle");
     
     void Start()
     {
         animationComponent = GetComponent<Animator>();
     }
 
     void Update()
     {
         //IDLE STATES ________________________________________________
        
        if (Input.GetKeyUp(KeyCode.W) && Input.GetKeyUp(KeyCode.S) && Input.GetKeyUp(KeyCode.A) && Input.GetKeyUp(KeyCode.D))
         {
            
             Debug.Log("idle ANIME");
             animationComponent.SetTrigger(idleHashId);
             
         }
        
         //ACTION STATES ________________________________________________
        
        else if (Input.GetKeyDown(KeyCode.W))
         {
             Debug.Log("jog ANIME");
             animationComponent.SetTrigger(jogHashId);
         }
        
        else if (Input.GetKeyDown(KeyCode.S))
         {
             Debug.Log("jog back ANIME");
             animationComponent.SetTrigger(jogBackwardsHashId);
         }
        
        else if (Input.GetKeyDown(KeyCode.D))
         {
             Debug.Log("strafe right ANIME");
             animationComponent.SetTrigger(strafeRightHashId);
         }
        
        else if (Input.GetKeyDown(KeyCode.A))
         {
             Debug.Log("strafe left ANIME");
             animationComponent.SetTrigger(strafeLeftHashId);
         }
       
     }
     
 }

thank you for your help its greatly appreciated!!

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

1 Reply

  • Sort: 
avatar image
0

Answer by Priyanka-Rajwanshi · Apr 18, 2018 at 04:50 AM

@Fibonacci_0_1_1 Your first condition would be true when you release W A S D simultaneously. For your query, remove the first if condition and place this condition at the end. I have also added a condition that the idle animation is currently not playing.

      else if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D)  && animationComponent.GetCurrentAnimatorStateInfo(0).shortNameHash != idleHashId)
      {
          Debug.Log("idle ANIME");
          animationComponent.SetTrigger(idleHashId);
      }
Comment
Add comment · Share
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

Follow this Question

Answers Answers and Comments

218 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation layer naming convention between enemies and player 0 Answers

How do i orginize 8+ movement animations? 1 Answer

Play simple animations on demand 1 Answer

making an arrowgrab animation play when attackdelay = 0. 0 Answers

Animation begins at start of Gameplay before colliding with trigger 2 Answers


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