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 commodore · Jun 08, 2012 at 02:45 PM · animationpingpongrewind

pingpong animation question

Hello,

How do I get an animation to play all the way through to the end while a key is pressed, and then after the key is released, rewind back to the beginning?

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
1
Best Answer

Answer by Scribe · Jun 08, 2012 at 03:01 PM

I haven't tested this so it may be completely wrong however I would guess you could do:

 animation.Play("ClipNameHere");
 if (Input.GetKey ("space")){
      animation["ClipNameHere"].speed = 1;
 }else{
      animation["ClipNameHere"].speed = -1;
 }

sorry if this isn't correct! As I said this isn't tested and I haven't used many animations lately :)

Scribe

Comment
Add comment · Show 6 · 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 Scribe · Jun 09, 2012 at 10:12 AM 0
Share

Why did my answer get voted down :( I tested it and it very almost works apart from at the end of the animation it restarts but that can be fixed probably by setting the animation to 'clamp forever'? could someone correct me if I'm wrong or give me a reason for the down vote please! :)

avatar image Bunny83 · Jun 09, 2012 at 11:22 AM 2
Share

I have no idea why it got downvoted. It's actually a very good approach. The only thing that's missing is: - Don't use wrapmode "Once" because it will auto-rewind the animation when it's done. Use ClampForever. - The animation time can go beyond the clips borders (smaller than 0 and greater than cliplength). You need to clamp the time between the borders. This can be done with the normalized time.

So this does work pretty well with wrapmode ClampForever:

 animation.Play("ClipNameHere");
 if (Input.Get$$anonymous$$ey ("space")){
      animation["ClipNameHere"].speed = 1;
 }else{
      animation["ClipNameHere"].speed = -1;
 }
 animation["ClipNameHere"].normalizedTime = $$anonymous$$athf.Clamp01(animation["ClipNameHere"].normalizedTime );
avatar image Bunny83 · Jun 09, 2012 at 11:28 AM 1
Share

Btw, this will also reverse the direction while the animation is playing. So if you release the key after 1/3 of the clip it just animates backwards the first 1/3

avatar image Bunny83 · Jun 09, 2012 at 12:51 PM 1
Share

Here i've created a sample build which shows how it works.

avatar image Scribe · Jun 09, 2012 at 06:02 PM 0
Share

Thanks @Bunny83 I thought I might have gone mad! :) Yeah I found I had the problem that it repeated itself, would setting the wrap mode to clampforever not work? or do you do it this way because it has better performance as I've heard clampforever isn't very good for performance?

Show more comments
avatar image
0

Answer by commodore · Jun 10, 2012 at 05:20 AM

Bunny your sample project is exactly what I needed! thank you

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 doesn't rewind on animation.Stop 3 Answers

Can the animation editor create local rotational data? 3 Answers

How do you rewind an animation that isn't playing? 2 Answers

Adding animation clips via script 2 Answers

Rewind/Play animations on demand. 1 Answer


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