Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 mats1105 · Jan 27, 2019 at 01:30 PM · triggers

OnTriggerExit2D calling when object is inside collider

Hi,


Short version:

How can detect if one collider is inside another and not touching any of the collider borders? Both colliders are triggers have rigid bodies. Read long version if you need more info.


Long version:

I have a 2D platformer game where my character is supposed to be able to climb ladders. I am doing this by checking when the player collider enters the ladder collider. When the player exits the ladder collider I am running OnTtriggerExit2D. My problem is that if my player is perfectly centered on the ladder and he starts climbing, his entire collider is inside the ladder collider and since the colliders aren't overlapping the OnTriggerExit2D is fired.


Se the video for the problem in action: Sample Gameplay


Both the colliders are triggers and have rigid bodies. One capsule collider and one composite collider.

I know I can make the ladder collider thinner so the player always hits one of the sides, but I can't figure out how to do that with a composite collider and it wouldn't be a proper solution anyways.


Here is the trigger code:

 private void OnTriggerEnter2D(Collider2D other)
     {
         if (other.gameObject.CompareTag("Climbable"))
         {
             playerController.climbing = true;
         }
     }

 private void OnTriggerExit2D(Collider2D other)
     {
         if (other.gameObject.CompareTag("Climbable"))
         {
             playerController.climbing = false;
         }
     }



Is there a simple fix for this?

Thanks in advance!

Comment
Add comment · Show 3
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 tormentoarmagedoom · Jan 27, 2019 at 10:27 PM 3
Share

As a moderator, i can say you that this is the perfect post :D Good job! and Good luck with your problem!

avatar image tormentoarmagedoom · Jan 30, 2019 at 09:43 AM 2
Share

@mats1105 Got it?

avatar image mats1105 tormentoarmagedoom · Feb 16, 2019 at 02:23 PM 0
Share

Got it, thanks! Sorry for taking so long to answer, school got in the way. I used the #3 solution :)

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by tormentoarmagedoom · Jan 27, 2019 at 10:37 PM

Good day.

Question #1

Did you tried OnTriggerStay?

Not the best solution #1

When you detect OnTriggerEnter, make the player trigger a little bigger to prevent that. So OnTriggerExit will only be executed whenr eally outside the ladder, so you make te player trigger smaller again.

Not the best solution #2

Calculate the distance from the ladder to the player before execute whats inside the OntriggerExit.

Possible solution

Create a new collider in the center of the ladder (by instantiating a prefab empty gameobject with only that collider. This methods also work with colliders of child objects)

Bye!

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 WagnerGFX · Feb 03 at 04:24 PM

I had the exact same issue and stumbled on this question, but ended up with a different solution. Since the question is from 2019, this might no have been available at the time.

My Solution

If you are using a Tilemap with the TilemapCollider2D and the CompositeCollider2D set as a Trigger then you should change Geometry Type to Polygon, otherwise the detection will only occur when overlapping with the Outline.

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

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

101 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 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 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

OnTrigger events not working 1 Answer

How do I spawn something if I'm touching something else in an array of children? 1 Answer

Is there any way to see exactly which triggers are overlapping? 1 Answer

How to enable passing through collider if speed is high enough at collision point 0 Answers

On Trigger Enter just triggers once for same object 1 Answer


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