How to detect if 90% of body collide in 2d

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hard

I want to change position of player which is rotating when it is 90% collide with door

:bust_in_silhouette: Reply From: jgodfrey

I can think of a couple of ways to approach this.

First, maybe you could just make the collision shape small (and in the center) of your visual object. Then, triggering a collision would require a good amount of overlap. That wouldn’t necessarily be the 90% you requested, but you might be able to approximate it.

Alternatively, to be more accurate, when a collision is triggered, maybe you could get the bounding boxes of the items in question (maybe via $CollisionShape2D.get_shape().get_extents()) and calculate the amount of overlap yourself. If it’s sufficient, do what you need to. Otherwise, ignore it.

Thanks for your help

hard | 2022-04-14 12:01