godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 69 forks source link

Allow for Characterbodies to have a weight assigned to them (for use in interaction with rigidbodies) #6536

Open swimmer248 opened 1 year ago

swimmer248 commented 1 year ago

Describe the project you are working on

I am working on a 2d puzzle platformer in which physics will play a major role. I want there to be rigidbodies and characterbodies interacting, such as a player (a characterbody) pushing a box (a rigidbody).

Describe the problem or limitation you are having in your project

Characterbodies have precisely zero effect on rigidbodies. To a rigidbody, a characterbody is weightless and massless, and thus lacks the ability to affect it in any way. This means that were I to introduce a rigidbody as an object in my world, characterbodies such as my player would be unable to influence it. While going back to how they interacted in godot 3 would work, I wish to have control over just how much an object has the capability to affect rigidbodies, and how much they affect it.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I would like for there to be a way to add a specific amount of "weight" to a characterbody. This would, of course, have no effect on the characterbody outside of interactions with rigidbodies. When a characterbody moves and slides into a rigidbody, it will push the rigidbody with strength based on its own weight and velocity.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

In addition to the currently extant "floor", "moving platform", and "collision" dropdown menus in the characterbody inspector, there would be an additional "rigidbody interaction" menu, allowing you to alter the weight of the characterbody in relation to rigidbodies, in addition to any other necessary variables.

If this enhancement will not be used often, can it be worked around with a few lines of script?

I have not yet seen a workaround that would allow for satisfactory characterbody-rigidbody interaction. If there is a workaround, it is almost certainly quite complex.

Is there a reason why this should be core and not an add-on in the asset library?

This is a rather basic feature one would expect from any node with even a modicum of physics to it, and would make developing any game in which physics plays a major role far less of a headache.

yosoyfreeman commented 1 year ago

As i see it the whole point of a characterbody, which is a kinematic body, is to provide an encapsulated way to extend from. custom Interaction with physic objects is one of the reason one would choose a kinematic body in first place. There are infinite ways in which a dev could want to interact with a physic body and there is no general solution. Pushing rigidbodies should not be a responsibility of the character body itself. A kinematic body is about the motion of the body and its own movement. A character interacting with other is another layer.

I personally would not bloat the new implementation with things that will not cover lots of use cases.

swimmer248 commented 1 year ago

The problem is that there's no interaction between characterbodies and rigidbodies. in 3.0 characterbodies could push rigidbodies, using infinite inertia. As of now, there are no ways to implement interaction between characterbodies and rigidbodies that doesn't look odd.

AThousandShips commented 1 year ago

I think CharacterBody is intended to be general and the many different ways a body interacting with physics with other bodies is far more variable, it's hard to provide a solution that fits everyone, and sometimes you just create something that fits no one well, and then it can be best to leave the more complicated things to individual users, you can use custom integration and other features of rigid bodies if this kind of complex physics interaction is desired, but keeping CharacterBody simple is I think important

yosoyfreeman commented 1 year ago

The problem is that there's no interaction between characterbodies and rigidbodies. in 3.0 characterbodies could push rigidbodies, using infinite inertia. As of now, there are no ways to implement interaction between characterbodies and rigidbodies that doesn't look odd.

That is not a problem, is an intended feature of a kinematic body. Infinite inertia was not a real interaction between characters and physics objects, just a hack.

As for "not being ways to implement interaction", is not true. There are many ways in which interaction between Character Bodies and Kinematic Bodies can be achieved in way better ways than the infinite inertia approach.

Kinematic to Rigidbody interaction by KidsCanCode as an example

If you really need a character that reacts to the whole physics simulation as any other object in your scene a character based on a RigidBody may better for what you are looking for.

swimmer248 commented 1 year ago

That's great and all if you want to push things with a constant speed, but with a character that gains momentum, it appears to break. I am unable to push things with my character, for instance. Being able to continue gaining velocity against a wall, due to the wall giving way, would be quite helpful.

AThousandShips commented 1 year ago

Have you tried using rigid bodies? Tried experimenting with different approaches?