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 enginehouse · Jul 16, 2012 at 09:00 AM · animationjavascriptwalkqueuecycle

how alternate walk cycle javascript

Hi all, I'm very very new to coding (3D artist by trade), but am trying to create a simple walk cycle that is broken into 2 halves. I've baked the keys for this, imported to unity, split the animations in the inspector. I have: idle walk start animation - where character puts left leg forward right foot forward animation left foot forward animation stopping with right foot stopping with left foot

For now the character will only move in one direction, and all I'm trying to do at the moment is get the animations to play in the correct sequence. Here's the code I have so far: (using javascript)

function Update () { if (Input.GetKeyDown("left")) leftStart(); }

 function leftStart ()
 {
  animation.PlayQueued("left start");
  
  if (animation.IsPlaying("left start") && Input.GetKeyUp("left"))
  rightStop();
  
  else if (animation.IsPlaying("left start") && Input.GetKey("left"))
  walk();
 }
 
 function walk ()
 {
  animation.PlayQueued("right forward");
  animation.PlayQueued("left forward");
  
  if (animation.IsPlaying("left forward") && Input.GetKeyUp("left"))
  rightStop();
  
  if (animation.IsPlaying("right forward") && Input.GetKeyUp("left"))
  leftStop();
 }
 
 function leftStop ()
 {
  animation.PlayQueued("left stop");
 }
 
 function rightStop ()
 {
  animation.PlayQueued("right stop");
 }


I've tried putting all of the if statements into the main function, having lots of functions, re-arranging everything, trying: if (animation["left forward"].enabled == true) instead of is.Playing, but each has a different and wrong behaviour. My suspicion is that something is going wrong with the GetKeyDown part, as if I repeatedly tap the left button it seems to work a bit better, but of course this isn't what I want. My other suspicion is that I ought to leave scripting well alone and stick to 3D artwork! But if someone can help me it would be much appreciated.

Comment
Add comment · Show 1
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 syclamoth · Jul 16, 2012 at 11:08 AM 0
Share

Save yourself the trouble, and look up the Unity Locomotion System. It's far more fully featured than anything you or I could write, and it's already been made. It's a free download, too!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by enginehouse · Jul 16, 2012 at 01:35 PM

cool thanks. I'd come across this before but assumed it was only for procedural animation? Does it also work for pre-keyed?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

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

Animation Won't Start 3 Answers

How would you make a shapeshifting mechanic in a game? 1 Answer

John Lemon Popping While Walking 0 Answers

Playing sprint animation with vertical axis? 0 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