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 SirBoboHobo · Mar 21, 2015 at 09:07 AM · collisionphysicstrigger

collider doesnt work the 2nd time

I have a platform with a game object attached to it that checks when something enters it, when my player enters it, it will disable its collider and when it exits it will re enable it. what it does is disable, collide with the platform once, and when it comes back down it disables it again for some reason... i have a gameobject attached to the ball with a trigger. void OnTriggerEnter2D(Collider2D other){ player.collider2D.enabled = false;

     }
     void OnTriggerExit2D(Collider2D other){
         player.collider2D.enabled = true;
     }

the script on the platform gameObject^

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 Priyanshu · Mar 21, 2015 at 09:49 AM 0
Share

You have a platform with the above script?

What is gameobject attached to the ball with a trigger you describe. Is it a seperate Object than Player and Platform?

avatar image SirBoboHobo · Mar 21, 2015 at 11:06 AM 0
Share

its a child of the Player, since when the player enters the trigger of the platform it gets disabled and i can't re enable it.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Priyanshu · Mar 21, 2015 at 11:20 AM

Basically what must be happening is when the child object enters platform (OnTriggerEnter2D executes) , Player collider is disabled.

But when child exits (OnTriggerExit2D executes), Player collider is Enabled.

But when a collider is enabled inside another collider OnTriggerEnter2D is called

. This enabling of player's collider inside Platform might be disabling it again by calling OnTriggerEnter2D again..

To avoid this you must check if the Collider2D "other" does not belong to player. If does not then execute the following code.

Comment
Add comment · Show 6 · 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 SirBoboHobo · Mar 21, 2015 at 11:28 AM 0
Share

Basically the same thing as checking if velocity>0 to disable collision and velocity<0 to enable it back again, but i was having problems with checking for velocity because sometimes the ball would get stuck in the middle of the platform since its velocity changes within platform bounds. and I didn't understand your explanation really.

avatar image Priyanshu · Mar 21, 2015 at 12:18 PM 0
Share

Grey : Player

Pink: Child of player

Black: platform

alt text

What I understood was when 'pink' enters 'black'. Collider of 'Grey' disables.

alt text

When 'pink' exits 'black'. Collider of 'black' enables.

Correct?

1.png (7.6 kB)
2.png (7.5 kB)
avatar image SirBoboHobo · Mar 21, 2015 at 01:03 PM 0
Share

What I understood was when 'pink' enters 'black'. Collider of 'Grey' disables.

When 'pink' exits 'black'. Collider of ' grey' enables.
avatar image Priyanshu · Mar 21, 2015 at 04:33 PM 0
Share

When 'pink' exits 'black'. Collider of 'black' enables.

Yes sorry i meant - When 'pink' exits 'black'. Collider of 'grey' enables.

avatar image Priyanshu · Mar 21, 2015 at 04:34 PM 0
Share

Now: Pink enters black. Grey's collider disabled.

alt text

Pink exits black. Grey's collider enabled.

alt text

3.png (6.7 kB)
1.png (7.1 kB)
Show more comments

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

22 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

Related Questions

If trigger hit, spawn it 1 Answer

Does the "Layer Collision Matrix" affect triggers? 1 Answer

Collission and Trigger on Same object 0 Answers

Question about collision and trigger 2 Answers

OnTriggerStay still called after moving a parent gameobject 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