Area node cant detect physics bodies using custom collision shapes. What am I doing wrong?

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

I used Blender to make my mesh and tried importing it as .obj,.dea,.gltf and .glb. I tried naming the mesh with the extension ‘-colonly’ and even tried just importing it as plainly as possible. pairing it with a static body seems to work right but with an Area node things stop making sense for me. I chained it to emit a signal to a script to print out what’s inside the custom collision area but nothing happens. Am I doing something wrong? I might be asking such a noobish question but I’m on my last leg with this thing, any help would be really appreciated :frowning:

:bust_in_silhouette: Reply From: Magso

Is it convex or trimesh? Convex has volume whereas trimesh is just surface collision.
If you put KinematicBody inside of both a convex and trimesh area and toggle the CollisionShape disabled properties repetitively, only the convex area will call the body_entered signal.

thanks bud but I think I want to avoid using convex collision shapes for a while, on the bright side I think I found a work around :slight_smile:

19PHOBOSS98 | 2020-04-26 14:48

:bust_in_silhouette: Reply From: 19PHOBOSS98

Since they fixed the Area Node to detect concave collision shapes in 3.2.1I think I found a “hack”. Area Nodes can’t use concave collision shapes as their own shape but they can detect them using a primitive shape.

Instead of having an Area Node with the custom collision shape sit and wait for a PhysicsBody to trigger a response we can have a PhysicsBody with the custom collision shape sit and wait for a small ‘mobile’ Area Node (using a primitive collision shape) to trigger a response!

With a StaticBody holding the custom collision shape and the Kinematic/Rigid Body carrying a small Area node we can simulate the interaction akin to a player walking into a trigger area but instead the trigger area can be any shape we want to be!

Imma noob so I’m not so sure if this is something old or if somebody out there already came up with the idea so apologies if I sound too exited of coming up with this alone.

update: for anyone interested, there’s a slight kink to this method tho, it can’t get a good read of whether or not the player is inside/out of a convex shape. when I tried using the body enter/exit signal it started flinging both signals at the same time. I think it has something to do with the convex shape lacking “volume” and only colliding with the player’s area node only “skin-deep” that is when the surface of the shape passes thru the area node it “enters” and then “exits” it as the player gets fully engulfed by the convex shape. I tried using a toggle, triggered by the body enter function, but it’s janky.

Maybe resizing the players area node whenever entering the shape to keep it in contact with the surface might be a good idea. Be back with the results.

19PHOBOSS98 | 2020-04-26 15:04

ok I’m back, scaling the area nodes size does help in staying in contact with the custom collision shape but it isn’t helpful when your trying to exit it.

the good news is I found a solution… but mind you it ain’t really as clean as I want it to be.

what I did was used 6 Raycast nodes sticking out of the player in every direction. Checking if they all have the same collider object, they can tell me if the player is inside or outside a custom collision shape whenever the “body_exited” signal was triggered by the player’s area node. I also called set_physics_processor(false) on all of them when not in use and turn them back on only when the “body_entered” signal was triggered.

for what it’s worth I also tried to compare the players velocity during “body_entered” and “body_exit” signal were triggered using their dot product to check if the player genuinely crosses over and used a toggle to check if its entering or exiting the shape. But this doesn’t work well with players teleporting into the shape and when players slightly skimming the surface.

The former method works great with teleporting players if you rig it up to check the 6 RayCasts after each teleport.

Don’t take my word for it, I’m a complete and utter noob at game engines. I’m not even sure if switching off physics processes for raycasts make a difference in performance…

19PHOBOSS98 | 2020-04-27 13:07

If anyone’s really interested: Here’s my preferred method: What you need: (set all three of these to a physics layer where they can collide with only themselves:) +An Area Node - stuck on a player/rigidbody +6 RayCast Nodes -also stuck to a player/rigidbody pointing out in all 6 axes for a mile or two +Your Custom Shape on a Static body

The important lines of code: on the player:

onready var check_axis = $Area/CollisionShape.get_children() #I placed the RayCasts under here for my player just cause…

func _ready():
for rays in check_axis:
rays.set_physics_process(false) #I really have a feeling that they take up too much processing power when they’re on

func is_inside():
for x in range(5):
if(check_axis.get_collider() != null):
if(check_axis.get_collider() == check_axis[x+1].get_collider()):
return false
return false
return true

func _on_Area_body_entered(body):
for rays in check_axis:
rays.set_physics_process(false) #luckily RayCasts apparently can remember the last thing they hit even when their physics_process is off

func _on_Area_body_exited(body):
prints(,“is inside:”,
prints(,“is outside:”,
The closest thing you can have as a custom collision shape for an Area Node is a convex collision shape generated from a mesh but sometimes they might not be in the “shape” you want them to be. They usually end up as a pile of CollisionShape Nodes of irregular shapes with gaps in between, giving inconsistent PhysicsBody detection.

This method allows you to use precise custom collision shapes as detection “areas”. Instead of using an Area Node with janky generated convex collision shapes to sit and wait for a PhysicsBody to trigger a response, we use a StaticBody holding the precise custom collision shape to sit and wait for an Area Node attached to a player to trigger a response.

19PHOBOSS98 | 2020-04-27 13:08

sorry if I ramble on and on about this, it’s just that I’m not so sure if all that I figured out is old news or not. Might as well write it all down to make sure for the sake of documentation

19PHOBOSS98 | 2020-04-27 13:13