Hey,

how would I go about let's say: Car with doors that can fall off?

I thought about two approaches, by looking at some Godot videos, but I don't really like them that much.

1) Since I would create the whole car in some DCC (blender obviously :D), I would have set it up like this: Car_body Doors Tires etc.

So Car_body is parent, and other objects will be children. After import, the heirarchy won't change. Now, first thing is, how do I handle collision. It would be OK to have one convex box at first, but if one of the doors fall off, I would need there to be a hole. So let's say I create collision bodies for every single object. Now, how do I make them not register each other when that close together? I don't wan to use layers, since it does not really fit. (I would have to put every detachable object in different layer. Front doors could not only register body, but back doors as well). In UE4 there was this feature called "Weld" which did the exact thing. I need multiple collision shapes interact as one.

I know about this, but does it mean that they don't "fight" between themselves?

Now let's say I got some damage and one of the doors should fall off.

What I'd like to do is just take the node representing one of the doors and reparent him to the world. Is it viable approach?

Because in one of video tuts, I've seen he updated the position of item in every _physics_process() call (when picked up). Which seems stupid to me.

TL;DR:

Is there some way of making multiple collision shapes act as one. Should I reparent child node to the scene root or is there some other approach to dropping/picking objects.

Also, I am talking about 3D. Sorry I did not mentioned.

If you want to use a bunch of RigidBody nodes but you do not want them to collide with each other (and do not want to use separate layers, which I agree would be difficult), you can use the add_collision_exception_with function in PhysicsBody (documentation).

Then you could have your car composed of several separate RigidBody nodes, and when the car is damaged and the door falls off, just change the mode in the RigidBody node to MODE_RIGID and call remove_collision_exception_with to make it collide with the rest of the car. The hard part with that approach might be getting all of the RigidBody nodes to react to the physics world and collide together when the car is intact, since you will need to sync the positions (and velocities) between all the nodes. I'm not sure how you could handle this right off, but maybe you could use a RigidBody with a convex collision shape of the intact car, and then update all of the separate pieces of the car with that? I dunno, you might need to experiment.

I found this Reddit post that might be helpful, though it looks like it is for attaching RigidBody nodes and keeping them attached, rather than having multiple RigidBody nodes work together that can come apart.

Another thing you could do is kinda fake it, by having the whole car use a single collison shape, and when the door "falls off", just hide the door mesh and instance a RigidBody door scene at the position the door would be. It isn't technically accurate, but depending on your project and/or use case, this might work as a solution.

I done stuff like this in other engines with joints. Just put one (or two) joints to keep the door closed and remove them when it breaks. Not sure it works with Godot, though.

@TwistedTwigleg said: The hard part with that approach might be getting all of the RigidBody nodes to react to the physics world and collide together when the car is intact, since you will need to sync the positions (and velocities) between all the nodes.

That's what I actually don't want. If I understand correctly, When the car would be without damage, I want to use only one convex shape. No colliding between the bodies. But if I were to take some damage, I did not want to create instance of rigid body at that moment to have physics applied. So actually this approach seems pretty good.

So I guess, what I'll do is I'll create everything as separate body and somehow disable them while being attached to the car. Anyway thanks :)

@cybereality said: I done stuff like this in other engines with joints. Just put one (or two) joints to keep the door closed and remove them when it breaks. Not sure it works with Godot, though.

Yes, me too, however just attaching something via joints would not be enough as the doors would collide with the car body all the time.

Also any idea about the reparenting stuff?

@ligazetom said: Also any idea about the reparenting stuff?

I have not tried reparenting nodes myself, but I think, in theory, you can use the duplicate function in Node (documentation), add it as a child to whatever you want as the new parent, and then delete the old node.

I have not tested it, but a function like this might work:

func reparent_node(node_to_reparent, new_parent):
	var clone = node_to_reparent.duplicate(node_to_reparent.DUPLICATE_USE_INSTANCING)
	new_parent.add_child(clone)
	node_to_reparent.queue_free()
	return clone
3 years later