• 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 /
  • Help Room /
avatar image
0
Question by Dusho · Dec 17, 2015 at 11:17 AM · colliderontriggerenterlocalposition

OnTriggerEnter2D not fired while OnTriggerStay2D is

when changing child position (using transform.localPosition), OnTriggerEnter2D is not triggered on child object while moving and evidently colliding (even OnTriggerStay2D s triggered) Only colliders are attached to objects, no RIgidbody2D. Triggers are working properly when not changing localPosition in Update().

 if (riding == RidingState.MovingRight)
         {
             transform.localPosition = Vector2.Lerp(leftPos, rightPos, relU);
             relU += Time.deltaTime * slideSpeed;
 
             if (relU >= 1f)
             {
                 relU = 1f;
                 transform.localPosition = new Vector3(rightPos.x, rightPos.y, 0);
                 riding = RidingState.StableRight;
             }
 
         }
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
Best Answer

Answer by hexagonius · Dec 17, 2015 at 12:11 PM

That's correct behaviour. changing position is teleporting, not moving. use AddForce or change velocity, but do not alter the position. stay is triggered because an overlap exists after moving into another.

Comment
Add comment · Show 3 · 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 Dusho · Dec 17, 2015 at 12:24 PM 0
Share

But there is no Rigidbody2D on the object, there is one on the parent, but not on the child object, child has just BoxCollider2D as trigger. So there is no way to get Enter and Exit fired purely on collider triggers.. Somehow I missed that in documentation. EDIT: and also I read, that there can't be rigidbody on parent and also child.. it must be then solved through joints..

avatar image hexagonius Dusho · Dec 17, 2015 at 12:38 PM 0
Share

well, the rigidbody combines its colliders (own and children) for$$anonymous$$g a compound. a script on the rigidbody reacts to all of them. last thing I never did but could work is changing the position of the child in fixed update, but I doubt it works.

avatar image Dusho · Dec 17, 2015 at 01:06 PM 0
Share

I tried moving it to FixedUpdate(), didn't help. And yes, you were right about combining colliders (I put the OnTriggerEnter2D in parent - where Rigidbody2D was), but again didn't work when the child was moving using localPosition (wasn't triggering Enter trigger again), only when it was stable.

But when I tried to put rigid body (turn off gravity) into child and then only set it's velocity to one of parent, everything started working like it should. Oh boy, Unity.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

35 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

OnTriggerEnter Issue - Collider problem 0 Answers

How to call an action from a script that is on the anonymous object you collide with? 1 Answer

[RESOLVED] OnTriggerEnter2D with 2 different missile types colliding with player PROBLEM 0 Answers

How do I differentiate between the triggers? 1 Answer

OnTriggerEnter doesn't work if the colliding object is not moving. Translating it by (0,0,0) fixes it. What's the problem? 4 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