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
0
Question by theedi80 · Jul 17, 2019 at 03:18 PM · collisioncollider2distrigger

GameObject with 1 top Collider IsTrigger and 1 bottom regular Collider problem.

alt text

Please have a look at the picture. What I am trying to do is to allow Obj A to be able to fall down on Obj B which is constantly moving and stay on it. Obj A also can crush other Obj B above it by jumping towards them.

I have added 1 polygon collider 2D with IsTrigger to cover the top part of Obj A and then added a box collider 2D to the bottom/feet of Obj A. When Obj A jump and hit an Obj B above OnTriggerEnter2D will trigger which is correct. However, when Obj A fall down and touch an Obj B below both OnTriggerEnter2D and OnCollisionEnter2D will trigger which is not what I expect. I expect that box collider 2D will touch Obj B and trigger OnCollisionEnter2D only.

Why it has such behaviour and how could I solve this problem?

obja.jpg (30.8 kB)
obja.jpg (30.8 kB)
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
1
Best Answer

Answer by JonPQ · Jul 17, 2019 at 03:49 PM

well one solution would be to get rid of the trigger, and just use the collider and the direction and speed of A's Y movement.... up or down to control what to do when you hit something. e.g. if moving up and speed > smashThresholdSpeed, then smash B you could also then have a slower threshold to just jiggle B when its hit.... more flexible...

you could also try making the trigger on top of A very thin inY axis... and the box collider large... in case object A is moving down fast, say distance dy per frame... and dy> thickness of the current boxcollider... so when object moves down... it moves far enough in one frame, for both the collider and trigger to enter B.

Comment
Add comment · Show 4 · 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 theedi80 · Jul 18, 2019 at 12:51 AM 0
Share

Thanks for the advice.

The use of trigger is to prevent physics on Obj A when it jump and hits Obj B. If I don't use trigger then Obj A will act like jumping into a brick wall and fall down immediately but what I need is Obj A will go through Obj B which will transit into a blowing up animation.

I need Obj A's entire upper body to be able to collide with other objects too like A can run through a power up item so a very thin collider will not work for that purpose.

avatar image JonPQ theedi80 · Jul 18, 2019 at 05:02 PM 0
Share

if you cant change the sizes of the colliders, check the collision type... if its set to discrete... (one check per frame of movement, its still possible both your colliders move far enough in 1 frame to be triggerred) then try CollisionDetection$$anonymous$$ode.ContinuousDynamic. If the problem is caused by moving in dy more than the thickness of your collider per frame... then doing this might help. see... Rigidbody.collisionDetection$$anonymous$$ode https://docs.unity3d.com/ScriptReference/Rigidbody-collisionDetection$$anonymous$$ode.html

avatar image theedi80 JonPQ · Jul 19, 2019 at 03:08 PM 0
Share

Just tried changing collision detection to ContinuousDynamic and still same problem. In fact collision gets trigger earlier than discrete mode.

Anyway, I have found another way to prevent this. In OnTriggerEnter2D I added a check of Obj A's rigidbody2d.velocity.y if it's negative means it is falling down so just exit the function while if it's positive it must be a jump so transit to blowing up animation.

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

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

Problem with method Collider2D.isTouchingLayers() 4 Answers

how do I enable collision? 0 Answers

Tilemap Collider 2D preventing objects from moving 2 Answers

How to the detect what side of the player is colliding with a object in a tilemap 2 Answers

How do I stop characters from standing on top of each other 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