How to tell if a KinematicBody is completely inside of any StaticBodies?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Atort
:warning: Old Version Published before Godot 3 was released.

In my game the player can teleport but can_teleport_to(location) only checks for intersection and not if the player’s collision shapes are inside of anything. I understand why although I argue the method name should be changed.

Anyway I tried to get around this by casting a ray from the teleport location to the current location of the player and if the surface normal of the first collision is facing away from the ray (using the dot product and a vector) the teleport target is inside something. This can be repeated with an additional ray going straight up if the first collision is the heightmapped terrain to account for hollow bottomed bodies. The only issue is if static bodies are intersecting but it’s not an issue for my game.

I was happy with this thinking I was onto a simple, efficient solution but when I raycast through a collision surface the reported normal of that surface is reversed (even in the same collision position) if the ray is coming from the other side, making this method impossible to use.

As a rough example this is what gets printed:

(collider:[StaticBody:705]), (collider_id:705), (normal:(0, 0, 1)), (position:(-2.094037, 0.04, -11.912519)), (rid:[RID]), (shape:0)
(collider:[StaticBody:705]), (collider_id:705), (normal:(-0, -0, -1)), (position:(-2.142617, 0.04, -11.912519)), (rid:[RID]), (shape:0)

I don’t know if this raycast thing is a bug but I’m stumped regardless.

:bust_in_silhouette: Reply From: dennisb

Have you tried multiplying the reported normal by -1 ? doing this might invert the direction of the normal, which is what you want right ?