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 Ouija · Mar 10, 2015 at 01:20 AM · animationcollidertriggerontriggerexitontriggerstay

Trigger animation going crazy

When player stays on trigger, it only plays "moveOut" and it loops/repeats crazy, the loop is takin off the animation. So no idea whats going on.

     void OnTriggerStay(Collider other)
     {
 
         animation.Play("moveOut");
     }
     
     void OnTriggerExit(Collider other)
     {
 
         animation.Play("moveIn");
     }
 }

Comment
Add comment · Show 2
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 Kumo-Kairo · Mar 10, 2015 at 06:50 AM 0
Share

What do you expect, you call animation.Play every physics tick, about 40 times per second, giving it no rest. Of course it will play it constantly

avatar image Ouija · Mar 10, 2015 at 07:02 AM 0
Share

do you have any ideas to help? I know whats happening, just no idea how to fix it, new to scripting in c#

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by mustafatufan · Mar 10, 2015 at 09:48 AM

That is normal. If you want to animate just once, try "OnTriggerEnter" instead of "OnTriggerStay".

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
1

Answer by HarshadK · Mar 10, 2015 at 06:51 AM

I guess what you are looking for is:

  void OnTriggerStay(Collider other)
  {
      if(!animation.IsPlaying("moveout")) 
          animation.Play("moveOut");
  }

So we only play the moveout animation if it is not already playing while inside the trigger so that the play is not triggered every FixedUpdate.

Comment
Add comment · Show 7 · 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 Ouija · Mar 10, 2015 at 07:04 AM 0
Share

I tried what you said, but moveOut still keeps repeating itself over and over and moveIn doesnt play at all. No change hmmm

 void OnTriggerStay(Collider other)
     {
         if(!animation.IsPlaying("moveOut")) 
             animation.Play("moveOut");
     }
     
     void OnTriggerExit(Collider other)
     {
         animation.Play("moveIn");
     }
avatar image HarshadK · Mar 10, 2015 at 07:13 AM 0
Share

Looks like your moveIn animation is actually making character get back in trigger and then the moveout animation plays and this out and in keeps repeating.

Try:

  void OnTriggerStay(Collider other)
  {
      // If no other animation is playing then only we play moveout animation
      if(!animation.isPlaying) 
          animation.Play("moveOut");
  }
  
  void OnTriggerExit(Collider other)
  {
     // We stop any other animation playing and then play the moveIn animation 
      animation.Stop();
      animation.Play("moveIn");
  }
avatar image Ouija · Mar 10, 2015 at 07:20 AM 0
Share

haah well , the moveIn now works now which is great. But moveOut is still repeating itself : /

avatar image HarshadK · Mar 10, 2015 at 08:46 AM 0
Share

So do you want to run moveout only once when the player is in the trigger?

If so, then call the moveOut inside OnTriggerEnter rather than OnTriggerStay.

avatar image HarshadK · Mar 11, 2015 at 05:45 AM 1
Share

Is your moveOut animation set to loop. Check for this animation import settings in Inspector.

Show more comments
avatar image
1

Answer by DiNoGames · Mar 10, 2015 at 10:06 AM

If you only want to play it once, then you shouldn't call it in OnTriggerStay which occurs every frame the object is within the trigger.

Use OnTriggerEnter instead which occurs only once.

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 Ouija · Mar 10, 2015 at 09:00 PM 0
Share

Yeah I tried that, it makes sesne, butttt it still repeats itself, and it makes lil sense to why at this point : /

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

23 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

Related Questions

How to use OnTriggerEnter with multiple triggered objects? 1 Answer

OnTriggerStay instead of input 2 Answers

Possible to stop collider from "popping" through plane when re-centering? 2 Answers

Ask for trigger-collision inside Update() 1 Answer

OnTriggerStay Question 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