Hi guys,

I have some items in my project that the player should be able to carry around. He should also be able to drop or throw them. Very similar to the mechanics known from games like "Overcooked". So far I have solved this by making the items of type RidgedBody3D.

To carry the items around, I switch the Ridgedbody to "Freeze = true". That works quite well.

My problem now is that I have to do collision checks if, for example, you walk into a wall (StaticBody) with the item. This only triggers the events/signals OnBodyEntered if you set the values ​​in the Item(RidgedBody3d) script as follows:

ContactMonitor = true;
MaxContactsReported = 100;

BodyEntered += OnBodyEntered;
BodyExited += OnBodyExited;

Freeze = true;
FreezeMode = RigidBody3D.FreezeModeEnum.Kinematic; // <--- Important

The events only trigger in FreezeMode Kinematic. And that's where the problem lies. This way, when you carry the item around and then let it go, energy is applied to the item and it flies around.

Is there a way to avoid this?
I also read somewhere that it's not good to move RidgedBody3D objects manually in Godot. Should I avoid this and only use StaticBodies? Even if I then can't use the physics engine for throwing, for example....

Please give me your opinion! :-)

  • xyz replied to this.

    Mauschelbaer Your item doesn't need to be represented by a specific node setup or a single scene. As long as you hold all relevant data for this item in some place, you can instantiate different representations of the item, depending on the situation. So your item can be a rigid body in one situation, a character body in other situation or a non-interactive sprite in some third situation. Just swap the representation with the one that's most appropriate for the situation.

      xyz Thanks again for the quick reply!

      How should I imagine this? At the moment I have a scene for each item (e.g. Apple). Each item scene is of type ridgedbody3d. It has a script attached with the same name (e.g. Apple.cs) which inherits from the abstract script "Item.cs". This in turn inherits from Ridgedbody3D.

      What would your suggestion look like roughly described?

      • xyz replied to this.

        Mauschelbaer Determine which representations you need. Create a scene for each representation that can be customized to handle any item. Item.cs can then only inherit Node or even RefCounted but should be able to manage the representation scenes.

        There are other possible approaches but it really depends on how different the items can get in terms of functionality. If they differ only in visuals and some stats then you don't really need a new class for each item. In general, try to keep the number of classes as low as possible.