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 babyjay521 · Jul 28, 2012 at 02:17 AM · animationsframes

How can I trigger an animation to play at a certain frame in another animation?

Hello all! I've hit a bit of a bump in the road on this particular project of mine, and thought I'd turn to Unity Answers for help.
Basically I have this walk animation that plays when the 'W' key is being held. And I want a jump animation to interrupt it when the 'space' key is hit. The thing that I'm struggling with though is making the jump animation play at the 10th frame of the walk animation. What I mean is I want the animation to continue playing and then play the jump animation at the 10th frame. I tried using a while loop to make the jump animation yield until the walk animation got to the tenth frame, but it isn't working. Here's the code:

var forwardspeed:float=.5;

animation["run"].speed=1.4; animation["walk"].speed=.1;

function Update (){ animation.CrossFade ("idle");

if(Input.GetKey(KeyCode.W)){

directionforward=Vector3.forward*forwardspeed*Time.deltaTime; transform.Translate(directionforward*forwardspeed); animation.CrossFade ("walk"); if(Input.GetKey(KeyCode.Space)) {

//plays the "walk jump" (jump specific to the walk)
walk_Jump();

}

}

 function walk_Jump(){
 //frames per second=24 This bit of code gets the current frame
     var animationLengthWalk=animation["walk"].length;
     var framelength=animationLengthWalk/20;
     var animationLengthJump=animation["jump"].length; 
     var currentTime= animation["walk"].time % animationLengthWalk;
     var currentFrame= currentTime*24;

if(currentFrame!==10){ //this should continue yielding until the walk animation's current frame equals 10 while(currentFrame!==10){ yield; }
animation.Play("jump"); yield WaitForSeconds(animationLengthJump);

     }

else{

     animation.Play("jump");
     yield WaitForSeconds(animationLengthJump);
     
 

 }
 }

What am I doing wrong here? Thanks in advance!

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
1

Answer by Seth-Bergman · Jul 28, 2012 at 02:34 AM

The best way I know is using animation.normalizedTime

this is a float from 0 (the first frame) to 1 (the last frame)

animation.length returns a float length in seconds

not what you want here

just say

 if(animation["walk"].normalizedTime >= .3) // or whatever 
 {
 //jump!
 }

desired frame / total frames

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 babyjay521 · Jul 29, 2012 at 12:53 AM 0
Share

the issue is more getting the animation to play at that exact time...and waiting to play until it gets to that time. So for example, if I hit the 'jump' button at frame 3 of the walk animation, I want the walk animation to continue playing until it gets to frame 10, and then jump. I have the whole frame thing worked out, it's just getting the jump animation to wait...

avatar image babyjay521 · Jul 29, 2012 at 12:53 AM 0
Share

But thanks for you quick response and effort to help!

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

6 People are following this question.

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

Related Questions

3DSMax animations issue with Unity 0 Answers

Unity 5.5 Playing inside an animation forward and backwards. 0 Answers

How to remove animation frames? 0 Answers

Anyone know how to use Unity 5.1 - 5.2? (Animator Controllers and such) 0 Answers

Animation transform and player position issue 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