godotengine / godot-proposals

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

Add an equivalent of `PhysicsServer.area_set_monitor_callback(area: RID, callback: Callable)` for physics bodies #4881

Open SmartySmart702 opened 1 year ago

SmartySmart702 commented 1 year ago

Describe the project you are working on

Game with many rigid bodies.

Describe the problem or limitation you are having in your project

I'm creating physics bodies using PhysicsServer3D.body_create() but cannot use signals like "body_entered". Not 100% sure if this it not possible or if I just dont know how.

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

It would allow us to use signals like "body_entered", "body_exited" and "sleeping_state_changed" for physics bodies that are created using PhysicsServer3D.

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

We already have area_set_monitor_callback(area: RID, callback: Callable). We should have the same for bodies.

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

You can use a rigid body nodes instead but this comes with a performance cost. Fine for few physics objects but if you have many you want every bit of extra performance you can get.

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

We have this for areas and we should have this for bodies too.

Calinou commented 1 year ago

When using servers directly, you cannot use signals because there are no nodes to connect from/to.

SmartySmart702 commented 1 year ago

Guess nooby me got confused a bit with signals and callbacks but this proposal is still valid right? area_set_monitor_callback(area: RID, callback: Callable) but for bodies.

JohnPandich commented 3 weeks ago

I thought it might be prudent to add my use case for this feature. I am working on migrating collisions in scenes to working directly on the physics server so I can bypass spikes in "physics time" (and thus frame stutters) when loading chunks. One major step in this process is replacing any corresponding signals with manual calls to that signal's Callable in area_set_monitor_callback and area_set_area_monitor_callback. Having these functions for bodies would allow me to develop a complete solution.