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 /
  • Help Room /
avatar image
0
Question by bathorsthroat · Nov 08, 2017 at 09:55 PM · movementanimatorcontrollerdirectionkeyboard

Animations are not playing with certain directions?

Hello everyone! So I'm trying to get four-way movement with a 3D player character working with both keyboard and controller. The player's Animator is using a 1D blend (0 = idle, 0.5 & -0.5 = walk,). The issue is that for some reason my Walk right (0.5) and Walk Left(-0.5) animations will play when the Horizontal Axis on the keyboard or controller are used. BUT The walking animation doesn't play when my character is moving forward or back. I'm sure I'm making some sort of mistake I just don't know what.

Side note: My character continues moving(sliding) after I've stopped walking. This only happens when using the keyboard and not with the controller. I'm not sure if this is related to the above problem or not.

 //Gets Attached Players Animator
         playerAnimator = playerObject.GetComponent<Animator>();
 
                 
         //Forward/Left-Right Param
         var inputy = playerAnimator.GetFloat("InputY");
 
         
 
         //Movment Controller
         if (Input.GetAxis("Vertical") >0)
         {
 
             transform.position += Vector3.forward * Time.deltaTime * moveSpeed;
             playerAnimator.SetFloat("InputY", 0.5f);
             
         }
         
 
         if (Input.GetAxis("Vertical") < 0)
         {
             transform.position += Vector3.back * Time.deltaTime * moveSpeed;
             playerAnimator.SetFloat("InputY", -0.5f);
 
         }
         
 
             if (Input.GetAxis("Vertical") == 0)
         {
             transform.position += Vector3.zero * Time.deltaTime * moveSpeed;
             playerAnimator.SetFloat("InputY", 0);
 
         }
 
         if (Input.GetAxis("Horizontal") > 0)
         {
             transform.position += Vector3.right * Time.deltaTime * moveSpeed;
             playerAnimator.SetFloat("InputY", 0.5f);
 
         }
         
 
         if (Input.GetAxis("Horizontal") < 0)
         {
             transform.position += Vector3.left * Time.deltaTime * moveSpeed;
             playerAnimator.SetFloat("InputY", -0.5f);
 
         }
         
         if (Input.GetAxis("Horizontal") == 0)
         {
             transform.position += Vector3.zero * Time.deltaTime * moveSpeed;
             playerAnimator.SetFloat("InputY", 0);
 
         }
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

· Add your reply
  • Sort: 
avatar image
0

Answer by jchester07 · Nov 11, 2017 at 09:04 AM

Why are you setting it to 0.5f? Are you reserving the value of 1 for other things?

Basically, Axis are just between -1 to 1. You can easily set the values like this

 float horizontalMovement = Input.GetAxis("Horizontal");
 // if you want to keep it at 0.5, do this.
 // horizontalMovement /= 2f;
 transform.position += Vector.right * horizontalMovement * Time.deltaTime * moveSpeed;
 playerAnimator.SetFloat("InputY",horizontalMovement);

Obviously, forward and back animation won't work because you set the same float (InputY) at the same value of 0.5f/-0.5f which is also the same that of the horizontal(left/right).

It's better that you should use 2D blend in this cases.

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

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

165 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

Related Questions

Top Down Character - Face direction of movement? 0 Answers

Air Control While Jumping? 1 Answer

Basic MOVE and JUMP script (Jump trouble) 2 Answers

How to adjust a GameObject's rotation to face it's moving direction ? 0 Answers

RuntimeAnimatorController not loading from script 4 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