How do I indirectly extend a class?

(Godot version 4)

So I’m trying to make a character_body but I want it to have the physics of a rigid_body except all my blue text (such as is_on_floor() and get_tree()) is messing up so I’m wondering how to extend 2 classes at once or something like that. (Please help it would be ideal if I could these answers before my game jam is done)

Why not using a RigidBody for your character?

So you are saying you want to extend two different things which you can’t, but why not use a character body for your player and make the objects that the player interacts with be a rigid body? Also you could put a raycast like this:
image

Which you can replace is_on_floor() with

@onready var ray_cast_2d: RayCast2D = $RayCast2D

ray_cast_2d.is_colliding() # Replace that with is_on_floor()

Lastly, a rigid body should not affect your get_tree() btw

I’m not 100% certain specifically what you’re asking in regards to the blue text. However, I have been in situations like this myself as I migrate to Godot. Coming from Unity, I still always think first with the mentality of ECS. In Unity, a Node is a Node is a Node, and its total behavior is the composite of all of the things that form that Node.

CharacterBody2D/3D and RigidBody2D/3D both derive directly from PhysicsBody2D/3D. And in addition, as far as a physics engine is concerned, it makes sense that both of these would conflict, even if Godot allowed you to inherit them both. It’s not a matter of multiple inheritance/components, it’s a matter of them both doing the same behavior (Managing their own position and pushing other objects) in two very different ways.

If I understand your question correctly in regards to the text:
The proper solution that I can see is to have any text or label nodes on your player, that must have angles and positions that are not be physics-based, simply use their own logic to set their position and angle. Try adding a script that simply rights their angle and positions them in a fixed relation to their parent CharacterBody2D. If it’s 3D, it’s better to just put them on the GUI instead of in the player, and again, position them in there.

1 Like