#Modular collisions?

12 messages · Page 1 of 1 (latest)

storm pewter
#

Hello, I'd like to create a system where I have a root object that handles the movement and collision, and children objects that each have their own collider that also double as colliders for the root. I believe that this can be done through code but I'd like to know if it's possible to do in the editor.

late fulcrum
#

I'm pretty sure as long as the root node is a physics body, you should be able to just add as many collision objects as you want.

lethal tundra
#

Are you wanting a root object, and child objects that can move independently?
Or just a root object with different colliders, but all move together from collisions?

storm pewter
# lethal tundra Are you wanting a root object, and child objects that can move independently? ...

the second one, the goal was to have a system where every child can independently detect their own collisions so that the child can run it's own logic on collision (taking damage, exploding, etc) while the parent handles the physical response.
Unfortunately I've come to realize that:
A) There's no way to detect a collision without calling a move_and function;
Which doesn't even matter because
B) Godot will not calculate characterbodies that are children of other characterbodies

#

To be clear in my original idea both parent and child were characterbodies

late fulcrum
#

That at least gets a starting point... not sure how to best detect collisions like that...

bronze bridge
#

You will need to do some fancy coding to do that
First for your child node, perhaps making it as area would work
Then when you parent it, duplicate child collision shape, then add it to parent

Child node can process its logic with area while parent get additional colshape

late fulcrum
#

I know Area has signals you can connect for this purpose...

#

You could also treat the move_and function call in _physics_process as a polling mechanism. When it returns a kinematic collision object with collision info, use the info to decide which child to send the info to to react on.

lethal tundra
# storm pewter the second one, the goal was to have a system where every child can independentl...

I messed around with having rigidbody children of a character body and came to some of the same realizations you did. What I did instead was making all of the rigidbodies siblings under a non-moving parent node2d. Then I made joints between the different rigidbodies I needed. In my case I wanted DampedSpringJoint2d - but painfully discovered the documentation is incorrect. They work, but there is no "maximum length" at the physics layer.

RigidBodies automatically handle collision to prevent "overlapping" and simulate physics. If you want two 2d balls bouncing off one another, that's what you should use.

It sounds like you want uniquely detectable hitboxes with their own logic processing on a single parent, kinda like a spaceship with various different modules on the surface. You can use a single CharacterBody2d as the parent with a collision area that covers the whole ship. Set the collision masks for layer 1, and make any physical object that you need to prevent overlapping also on layer 1.

#

Then you can add other child nodes that are area2ds with their own colliders, and link signals for their collisions back to the parent ship's script. Set those to different layers if you want them to collide with different things.