Swapping between CharacterBody2D and RigidBody2D in game

Godot Version

v4.3.stable.official [77dcf97d8]

Question

Hello! I am new to Godot and am using a CharacterBody2D for the player character but want physics applied to them in certain situations. Would it be possible to swap out the CharacterBody2D to a RigidBody2D when the action calls for it, and then swap back once the action is done?

I am thinking maybe it would be something to do with temporarily disabling one for the other, and then teleporting the disabled Body2D to where the enabled Body2D was and swapping?

Would this be viable, or am I just better off using only a RigidBody2D for the player character?

Using RigidBody2D would be good for a physics simulation that’s relatively more complex. For simpler movements, CharacterBody2D is more suitable as it makes body control easier. When dealing with complex simulations like rotation, you could consider using RigidBody2D.

Similar to CharacterBody2D, RigidBody2D also supports the concept of velocity. However, when continuously modifying the velocity, ensure you do it in the _linear_integration() method instead of the _physics_process() method. This improves the smoothness of the physics simulation.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.