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


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?

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.