• 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 Perrymanon · Feb 20, 2014 at 06:04 PM · animationtransformspeedplayanimationstate

I am attempting to play an animation in reverse and slow it down, But it only seems to play forwards.

Hello,

I currently have an animation play based on the transform of an GameObject(background). The animation plays when the object is at the correct transform. But what I cannot get it to do it to play the animation in reverse when it reaches the other end. I have seen on other questions that using a negative speed would get it to move in the reverse direction. But this does not seem to be the case, can anyone help me?

Here is the code I have been using.

 using UnityEngine;
 using System.Collections;
 
 public class CameraMenu : MonoBehaviour {
     
     public GameObject background;
     public Transform backgroundpos;
     public Animation MoveLeft;
     public float PlaySpeed = 0.01F;
     
     // Use this for initialization
     void Start () 
     {
         
         backgroundpos = background.transform;
     
     }
     
     // Update is called once per frame
     void Update () 
     {
         if(backgroundpos.position.x == 18)
         {
             
             animation.Play("MoveLeft");
             
             animation["MoveLeft"].speed = PlaySpeed;
              
         }
     
         if(backgroundpos.position.x == -18)
         {
             
             animation.Play("MoveLeft");
             
             animation["MoveLeft"].speed = -PlaySpeed; 
             
         }
     }
 }
 

   


Thank you in advance

Jack Perry

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
0

Answer by jimmycrazyskills · Feb 20, 2014 at 07:08 PM

Sorry if wrong , but I think you need to set the play speed before playing the clip , so try switching the two lines of code.

 animation["MoveLeft"].speed = -PlaySpeed; 
 
 animation.Play("MoveLeft");
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 Owen-Reynolds · Feb 20, 2014 at 09:42 PM 0
Share

Can set speed on the fly. One cute trick is ["walk"].speed = velocity.magnitude; every frame, so that Walk is always the correct pace.

avatar image
0

Answer by Owen-Reynolds · Feb 20, 2014 at 09:51 PM

Not sure how the background is moving, and how it gets to 18 or -18, but, checking == is likely the problem. Try <=-18 and '>=18'.

Computer numbers round funny, since they're really ten or so binary digits. If you add 0.1 ten times, you might get 0.9999999 or 1.000000001. So, if might be 17.900001 and jump past 18 to 18.00001. It's sort of like saying you want someone six feet tall. Not to the nearest inch, exactly six feet using lasers and GPS. You won't find anyone.

Adding +1 over and over is fine. Computers aren't goal junk. The problems are only when you use fractions. Think of how we have to write 1/3rd as 0.333333.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 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

Related Questions

Animation Stop and Stay 1 Answer

Creating a play/pause button for animations. 0 Answers

Animation ["1"].speed = 0; Doesn't work 2 Answers

[Unsolved] Playing animation backwords [Unsolved] 1 Answer

Accessing AnimationState in Animator 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