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 boxburn · Jun 19, 2013 at 03:12 PM · animationreverse

[Solved] Reverse animation

Hello, I am trying to build a simple digger which has a movable digging arm. So far the movement of the arm runs off of an animation which is triggered by the down arrow key. The issue I am running into is that once the animation has reached the end, if I try to move the arm back up with the up arrow key it simply resets the animation to the frame 1 position instead of reversing the animation. If my description isn't very helpful, hopefully you will understand what I am trying to achieve with my code.


Edit: I have managed to work out how to make my animation successfully pause when no keys are pressed, to play when the down key is pressed and to reverse when the up key is pressed. I am posting this code in hope that someone who needs it comes across it in the future.

 var Bend_1:Transform;
 var Bend1:AnimationState;
 
 var B1A:boolean = false;
 var B1B:boolean = false;
 
 function Start(){
        Bend1 = Bend_1.animation["Bend_1"];
        Bend_1.animation["Bend_1"].wrapMode = WrapMode.ClampForever;
 }
 
 function Update(){
     
     if(Input.GetKeyDown("down")){
         B1A = true;
     }
     if(Input.GetKeyUp("down")){
         B1A = false;
     }
     if(Input.GetKeyDown("up")){
         B1B = true;
     }
     if(Input.GetKeyUp("up")){
         B1B = false;
     }
 
     if(B1A){
         Debug.Log("B1A = True");
         Bend1.speed = 1;
         Bend_1.animation.Play("Bend_1");
         if (Bend1.time < 0){
             Bend1.time = 0;
         }
     }
     if(B1B){
         Debug.Log("B1A = True");
         Bend1.speed = -1;
         Bend_1.animation.Play("Bend_1");
         if (Bend1.time > 1){
             Bend1.time = 1;
         }
     }
     if(!B1A && !B1B){
         Bend1.speed = 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 Adamcbrz · Jun 19, 2013 at 06:08 PM

Unity3d animation speed is positive only. If you set it to anything below 0 it will assume 0. So you are telling it to play the first frame of the Bend_1 animation. You can do two things here to accomplish your task.

1) Go back to the way you made the animation and create a second animation for the up process.

2) Create a script that will loop through the animation and play the frames in reverse. Something like this might be a good reference http://answers.unity3d.com/questions/32753/ideas-for-animating-while-paused.html

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 boxburn · Jun 19, 2013 at 11:49 PM 0
Share

Setting the speed to -1 seems to do the job perfectly fine. I'm assu$$anonymous$$g that when using Wrap$$anonymous$$ode.ClamForever it creates a temporary - value on time as the code in the "if(B1A){" function I used works off detecting if the time is less than 0 which seems to work with no issues.

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

15 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

Related Questions

Can I make animations snap to a frame? 1 Answer

Reversing animation nullpointerexception 0 Answers

Set up Animator with specific seconds 1 Answer

Playing animation in reverse plays it once only! 0 Answers

animation wont reverse 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