Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 blackjard · Oct 27, 2012 at 05:17 PM · animationwalkreleasewasd

WASD release --- change animation

Hi guys, I am making a survival horror game and you can find a shotgun. However when you walk with the shotgun an animation plays that moves the shotgun from side to side. The Idea is that if your release all of the keys "WASD" it returns to the "Shotgun Steady" animation.

I made the following script: (2 animations: steady and walk)

 function Update () {
 if(Input.GetKeyDown("w")) {
 
     animation.Play("riflewalk");
 }
 
 if(Input.GetKeyUp("w")) {
 
     animation.Play("riflesteady");
 }
 
 if(Input.GetKeyDown("a")) {
 
     animation.Play("riflewalk");
 }
 
 if(Input.GetKeyUp("a")) {
 
     animation.Play("riflesteady");
 }
 if(Input.GetKeyDown("d")) {
 
     animation.Play("riflewalk");
 }
 
 if(Input.GetKeyUp("d")) {
 
     animation.Play("riflesteady");
 }
 if(Input.GetKeyDown("s")) {
 
     animation.Play("riflewalk");
 }
 if(Input.GetKeyUp("s")) {
 
     animation.Play("riflesteady");
     
     }
 }

When I Press W to move forward.. the animation plays, but I also press A to strafe a little bit to the left.. No problem the animation plays nicely. But when I release A again to move in a straight line, the animation stops (because of the 4 release commands)

Is there a way to combine all of those release commands in 1 return to the "steady shotgun" animation?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Piflik · Oct 27, 2012 at 05:42 PM

Something like that might work:

 if(Input.GetKey("a") || Input.GetKey("s") || Input.GetKey("d") || Input.GetKey("w")) 
     animation.CrossFade("riflewalk");
 
 else
     animation.CrossFade(riflesteady);
Comment
Add comment · Show 2 · 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
avatar image blackjard · Oct 27, 2012 at 05:52 PM 0
Share

Thanks man! I really like how it fades to the new animation! And it only changes to the Rifles$$anonymous$$dy animation when wasd are not pressed. Exactly what I wanted, Thanks!

avatar image blackjard · Oct 27, 2012 at 05:57 PM 0
Share

After I changed a couple of things it worked out fine :)

function Update () { if(Input.Get$$anonymous$$ey("a") || Input.Get$$anonymous$$ey("s") || Input.Get$$anonymous$$ey("d") || Input.Get$$anonymous$$ey("w")) animation.CrossFade("riflewalk");

else animation.CrossFade("rifles$$anonymous$$dy");

 }
avatar image
0

Answer by tmar2 · Oct 27, 2012 at 05:52 PM

In each of your tests for GetKeyUp, you need another statement that tests whether or not another key is currently down. So in your example, once "A" is released, before you change to the steady animation, first make sure that "W, S, or D" are not currently down. This should solve your problem.

Comment
Add comment · Show 1 · 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
avatar image blackjard · Oct 27, 2012 at 05:54 PM 0
Share

Thanks for the reaction! But the answer above is exactly what I want.

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

11 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

Related Questions

A node in a childnode? 1 Answer

idle > walk > run animation 1 Answer

Changing specific animation of a person 1 Answer

Animation... Unity 3D...Blender...3rd Person 2 Answers

Blender Animation Looping Delay Problem 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