Hi! I'm trying to detect collisions on CSG mesh, for interact with them but i can't find a solution! Yes, i cheked "use collision" parametr in CSG options(for any mesh and for combiner), and kinematic body is colliding and can move over the level, but maybe i want to print something when i colliding with the wall, how can i do this? I tryed use Area for connect signals like "body_entired", but it can see collisions on CSG meshes. And does this mean that i shoud to create a new Area with collision for any CSG mesh in my scene, and does godot have any other way to check collisions without Area? So... which way i shoud use for detecting collisions?
How to detecting collisions on CSG mesh?
I'm not sure on what would be the best way. It is strange that Area nodes do not see collisions with CSG meshes, maybe its a bug? Or perhaps because the CSG system can have multiple meshes and operations, maybe it ultimately becomes just one big CSG mesh and that's why the Area cannot see it.
Regardless, I'd say the best workaround depends on what you are trying to do. Using Area nodes around important parts of a CSG mesh may be the best solution if you only have a few key points you want to be able to detect collision with, like doorways, stairs, etc. The thing I worry with this solution is that it would not scale very well, but again, if you have a relatively small number of things to detect, using Area nodes is probably the most ideal solution.
If you want to just detect walls around the player, what you could try doing is using ray-casting and having all the objects that are walls on a single collision layer. Then you can cast a ray and if it collides with something, then you know there's a wall there. If you use short raycasts that are pointed in the same direction as the player's motion, then you could be relatively assured that if the raycast hits something, it is a wall in front of the player. It is not a perfect solution, but it does have the advantage of not needing additional setup per wall. Theoretically once the system is in place, it should just work for all walls. It also has the advantage of no additional work needed if you move the walls, change wall sizes, etc, unlike the Area-based solution that will require adjusting the collision shapes for each wall when its moved.
That's a couple ways of approaching the problem I can think of. Again, it really depends on your needs as to what may be the best workaround, but hopefully this helps a bit!
- Edited
@TwistedTwigleg said: I'm not sure on what would be the best way. It is strange that Area nodes do not see collisions with CSG meshes, maybe its a bug? Or perhaps because the CSG system can have multiple meshes and operations, maybe it ultimately becomes just one big CSG mesh and that's why the Area cannot see it.
Regardless, I'd say the best workaround depends on what you are trying to do. Using Area nodes around important parts of a CSG mesh may be the best solution if you only have a few key points you want to be able to detect collision with, like doorways, stairs, etc. The thing I worry with this solution is that it would not scale very well, but again, if you have a relatively small number of things to detect, using Area nodes is probably the most ideal solution.
If you want to just detect walls around the player, what you could try doing is using ray-casting and having all the objects that are walls on a single collision layer. Then you can cast a ray and if it collides with something, then you know there's a wall there. If you use short raycasts that are pointed in the same direction as the player's motion, then you could be relatively assured that if the raycast hits something, it is a wall in front of the player. It is not a perfect solution, but it does have the advantage of not needing additional setup per wall. Theoretically once the system is in place, it should just work for all walls. It also has the advantage of no additional work needed if you move the walls, change wall sizes, etc, unlike the Area-based solution that will require adjusting the collision shapes for each wall when its moved.
That's a couple ways of approaching the problem I can think of. Again, it really depends on your needs as to what may be the best workaround, but hopefully this helps a bit!
Thanks for the answer! But i use this code and everything seems to work
for i in get_slide_count():
var col = get_slide_collision(i)
var collider = col.collider
if collider.is_in_group('test'):
if collider is CSGBox:
print('CSGBox')
if collider is CSGSphere:
print('CSGSphere')
elif collider is StaticBody:
...
but as you might guess, other problems appeared...