0 votes

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 :(

asked Apr 25 in Engine by 19PHOBOSS98 (53 points)

2 Answers

0 votes

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.

answered Apr 25 by Magso (2,867 points)

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 :)

0 votes

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.

answered Apr 26 by 19PHOBOSS98 (53 points)

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.

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 "bodyexited" signal was triggered by the player's area node. I also called setphysicsprocessor(false) on all of them when not in use and turn them back on only when the "bodyentered" signal was triggered.

for what it's worth I also tried to compare the players velocity during "bodyentered" and "bodyexit" 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...

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 checkaxis = $Area/CollisionShape.getchildren() #I placed the RayCasts under here for my player just cause...

func ready():
for rays in check
axis:
rays.setphysicsprocess(false) #I really have a feeling that they take up too much processing power when they're on

func isinside():
for x in range(5):
if(check
axis[x].getcollider() != null):
if(check
axis[x].getcollider() == checkaxis[x+1].get_collider()):
continue
else:
return false
else:
return false
return true

func onAreabodyentered(body):
for rays in checkaxis:
rays.set
physicsprocess(true)
rays.set
physicsprocess(false) #luckily RayCasts apparently can remember the last thing they hit even when their physicsprocess is off

func onAreabodyexited(body):
if(is_inside()):
prints(self.name,"is inside:",body.name)
else:
prints(self.name,"is outside:",body.name)
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.

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.