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
1
Question by blunckalex · Jan 04, 2012 at 08:51 PM · animationcollidertriggerreverseclampforever

Problem with Reverse Animation

First off I know there are a bunch of "reverse animation problem questions..." but none seem to help with the problem I'm currently having.

I have an object with an animation, the animation is triggered when the player walks into a collider (set up as a trigger). Following script is attached to this collider:

 var targetObject : GameObject;
 var targetAnimation : String;
 
 function OnTriggerEnter(other: Collider) {
     targetObject.animation[targetAnimation].speed = 1;
     targetObject.animation.Play(targetAnimation);
 }
 
 function OnTriggerExit(other: Collider) {
     targetObject.animation[targetAnimation].speed = -1;
     targetObject.animation.Play(targetAnimation);
 }

the "targetObject" variable holds the said object which is to run it's animation and "targetAnimation" is the name of said animation.

the animation wrap mode is "clamp forever" by the way.

The problem I'm having now is following: 1. When the player walks into the collider the animation starts immediately (like I want it to) 2. Then When the Player leaves the collider the animation reverses with no apparent problem 3. But know the longer the player stands out of the collider and then steps back in...it takes longer for the animation to begin 4. The same when the player stays in the collider for a longer time, the reverse animation then also takes longer to start again.

I'm not really sure whats causing this and I want to thank you for any answers in advance. I hope to able to contribute to this great community with answers of my own once I'm a more skilled unity user ;-)

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

Answer by Owen-Reynolds · Jan 05, 2012 at 12:26 AM

Not tested, but...say your animation takes 2 seconds. The time runs 0,1,2,3,4... and anything past 2 counts as 2. When you reverse, it still counts down from 4 (counting as 2,) appearing to freeze until it hits 2. Likewise, it reverses to -1, -2... . Restarting has to count up to 0.

A fix might be adding:

 if(targetObject.animation[targetAnimation].time<0)
   targetObject.animation[targetAnimation].time=0; // onEnter

 if(targetObject.animation[targetAnimation].normalizedTime>1)
   targetObject.animation[targetAnimation].normalizedTime=1; // onExit

The idea of the ifs is if you happen to play 1/2 of the animation, you just want to play backwards from there -- not snap to the end then reverse.

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 blunckalex · Jan 05, 2012 at 12:35 AM 0
Share

Thank you Owen! Worked like a charm!

One more questions: is there a reason not to use "normalizedTime" in both cases ?

avatar image Owen-Reynolds · Jan 05, 2012 at 04:04 AM 0
Share

For 0, time and normalizedTime are the same (normalizedTime is just time scaled to 0-1) -- time is just shorter to write (and probably runs a hair faster, but not worth worrying about.)

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

Trigger transition to another animation. 2 Answers

4.5.2 animation BUG: 2D collider colliding with 2d trigger!!! 0 Answers

Can't click gameobject when over another trigger? 1 Answer

Trigger via Collider 1 Answer

How do you set up a trigger animation without going through the collider? 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