Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
6
Question by Reaper1121 · May 12, 2015 at 08:28 AM · c#animationreverse

Unity 5. Reverse animation play ?

Hello. How do i play animation in reverse? i been searching in internet and i found this:

 animation["Zoom"].speed = -1;

but its outdated now or i am doing this wrong. How do i play animation in reverse using unity 5? i start animation like this:

 bonuspanel.GetComponent<Animation> ().Play ();

soo it should be the same just like this:

 bonuspanel.GetComponent<Animation> ().speed = -1;

But speed does not exist. I hope someone can help me :)

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

4 Replies

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

Answer by HarshadK · May 12, 2015 at 08:38 AM

The solution by careyagimon is in this forum thread playing animation backwards.

It states:

I think you need to set when the animation is playing from first. Playing it backwards from 0.0 doesn't do anything. You need to play it backwards from the end of the animation.

Code (csharp):

 hand.animation["bridge"].speed = -1;
 hand.animation["bridge"].time = hand.animation["bridge"].length;
 hand.animation.Play("bridge");

Even better is if you can set the wrap mode to ClampForever. Play the animation once at speed 1 and then set the speed to -1 to reverse back to the starting state.

Comment
Add comment · Show 5 · 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 Reaper1121 · May 12, 2015 at 08:45 AM 0
Share

Like this? :

 using UnityEngine;
 using System.Collections;
 
 public class HideBonusPanelAnimStart : $$anonymous$$onoBehaviour {
 
     public GameObject showbonuspanelbutton;
     public GameObject bonuspanel;
 
     public void hidebonuspanel(){
         if (transform.position.y == 90) {
             bonuspanel.GetComponent<Animation> ().speed = -1;
             bonuspanel.GetComponent<Animation> ().Play ();
         }
     }
 }
 

speed does not exist i think i need to set what it is.

avatar image HarshadK · May 12, 2015 at 08:58 AM 0
Share

speed and time are the variables from AnimationState so you need to set them for specific animation state for which you want to change these values.

In example code above in the answer "bridge" is the name of the animation clip. So you need to do something like:

 Animation animation = bonuspanel.GetComponent<Animation>();
 animation["YourClipName"].speed = -1;
 animation["YourClipName"].time = animation["brYourClipNamedge"].length;
 animation.Play("YourClipName");

avatar image Reaper1121 · May 12, 2015 at 09:13 AM 0
Share

Like this? :

 using UnityEngine;
 using System.Collections;
 
 public class HideBonusPanelAnimStart : $$anonymous$$onoBehaviour {
 
     public GameObject showbonuspanelbutton;
     public GameObject bonuspanel;
     Animation animationbonuspanel;
 
     void Start(){
 
         animationbonuspanel = bonuspanel.GetComponent<Animation> ();
 
     }
 
     public void hidebonuspanel(){
         if (transform.position.y == 90) {
             animationbonuspanel["BonusPanel"].speed = -1;
             animationbonuspanel.Play("BonusPanel");
         }
     }
 }

It does not work

avatar image kalibcrone Reaper1121 · Jun 01, 2017 at 01:14 PM 0
Share

Also, don't forget to set things back to normal in order to play the animation forward again, ie:

 animation["YourClipName"].speed = 1;
 animation["YourClipName"].time = 0;
avatar image HarshadK · May 12, 2015 at 09:14 AM 0
Share

You are forgetting this line:

 animation["YourClipName"].time = animation["YourClipName"].length;

You need to call this line before calling the Play on your animation.

This line will set your animation to its last frame so that you can run it in reverse.

avatar image
13

Answer by brainpower · Feb 21, 2016 at 04:27 PM

Despite what Jasper_Moore said about speed multipliers, they worked for me.

Here's what I did:

1) Add a float parameter to the Animator (I called it "Direction"). Initialize its value to 1.0.

2) In the relevant animator state (in my case "Walking"), link the float parameter to the speed multiplier, like so: alt text

3) In your script, set the float parameter to -1.0 (for backwards) or 1.0 (for forwards), like this:

animator.SetFloat("Direction", -1.0f);


speedmultiplier.png (10.6 kB)
Comment
Add comment · Show 5 · 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 hoarfrost31 · Oct 21, 2017 at 06:29 PM 0
Share

This Doesn't work in unity 2017.2, $$anonymous$$aybe there is some bug.

avatar image methodin · Mar 31, 2018 at 07:01 AM 0
Share

This is the correct answer. Unity state machine was designed for parameters and having a parameter that you set of -1.0f or 1.0f to control the direction is the correct way to do this. Works perfectly.

If you are ins$$anonymous$$d already using a parameter for the multiplier then you can control it by making that speed negative as well.

avatar image DiegoMontania · Jun 07, 2018 at 02:34 AM 0
Share

Very userful, thank you!

avatar image NicolasCEMU · Nov 09, 2018 at 10:44 AM 0
Share

Definetely the best way to do it. Thank you !

avatar image henimex · May 30, 2020 at 10:10 AM 0
Share

perfectly solved my problem.

avatar image
1

Answer by Jasper_Moore · Aug 20, 2015 at 11:16 AM

While it would make sense to simply change the playback speed, or to create a float value in the animator for a speed multiplier, I have found it to be very inconsistent and buggy, if it works at all. The only consistent method I've found is stepping through the animation manually, like so:

public Animator myAnim; //Animation controller, assign in inspector.

private float animTime; //Tells us where we are in the animation's timeline.

private bool anim_Play; //Should the animation play?

void Update() {

     if (anim_Play && animTime < 1)           //If animation is toggled on
         animTime += 0.3f * Time.deltaTime;   //Increase animTime, Don't let animTime go beyond 1
     else if (!anim_Play && animTime > 0)     //If animation is toggled off/reversed
         animTime -= 0.3f * Time.deltaTime;   //Decrease animTime, Don't let animTime go below 0

     myAnim.Play("Some_Animation", 0, animTime ); //Step through animation manually

}

//Call this function to toggle forward/reverse. public void ToggleAnim() {

     anim_Play = !anim_Play;

}

This is a simple setup for a single animation (in my case, a door opening/closing). The animation will automatically idle at beginning and end. If you want it to do something else after playing, you'll have to experiment to work that out. Also, I used 0.3 for the speed multiplier, this can be adjusted to fit your needs. Hope this helps anyone having this problem!

Just to be clear, Here is what my animator view looks like for this setup: alt text


capture.png (42.0 kB)
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
avatar image
0

Answer by yankun1997 · May 05, 2017 at 09:34 AM

This is how i do,mine is quite straightforward

 private animatior anim;

 private float direction;

void update () {

      if (Input.GetKeyDown("space"))
     {
         anim.SetFloat("Direction", -1);
         anim.Play("WAIT02", -1, 0f);
     }

}

and you must set a float parameter in the animator (a transition) , in my case it's named direction.

hope it works for 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

27 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 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

Multiple Cars not working 1 Answer

Hey,Im making a game, and I need to reverse my 3D animation, how do I do that? 0 Answers

Distribute terrain in zones 3 Answers

Help with character movement and camera 1 Answer

[C#] Unity 2D: Changing animation when player is in motion. 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