godotengine / godot-proposals

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

[3.x] Bullet support improvements #4615

Open m4nu3lf opened 2 years ago

m4nu3lf commented 2 years ago

Describe the project you are working on

Physics-based sandbox with vehicle construction and destruction.

Describe the problem or limitation you are having in your project

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

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

I have locally patched Godot with the following features:

Additionally:

Given I already have most of the changes it would be a matter of polishing the code and creating a PR. Then I would need some help with testing (just to make sure I'm considering everything).

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

No, this requires to be implemented at the engine level.

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

This can only be implemented at the engine level.

Calinou commented 2 years ago

Could substeps also be implemented in GodotPhysics? They sound useful for racing games where simulation often runs at 200 Hz or more.

If this is possible, I assume substeps would also have to be implemented in 2D. It can surely help against tunneling issues while not increasing CPU usage as much as it would otherwise do when increasing Physics FPS.

m4nu3lf commented 2 years ago

Could substeps also be implemented in GodotPhysics? They sound useful for racing games where simulation often runs at 200 Hz or more.

If this is possible, I assume substeps would also have to be implemented in 2D. It can surely help against tunneling issues while not increasing CPU usage as much as it would otherwise do when increasing Physics FPS.

It should be possible to implement it for the other physics engines, both 2D and GodotPhysics. I haven't looked into it. But the basic idea is you just call "step()" multiple times internally. Bullet has some optimizations for substeps and it handles them internally. I could look into it, but given I have the code for bullet almost ready would probably be better to add support for Bullet first?

Calinou commented 2 years ago

I could look into it, but given I have the code for bullet almost ready would probably be better to add support for Bullet first?

Sounds good to me, but this feature will have to be ported to GodotPhysics so it can be added in master and preserved in 4.0.

m4nu3lf commented 2 years ago

I will have a look and see if the implementation is trivial, in which case I will just make the change. Question about the impulse feedback for joints (Which could also be implemented for GodotPhysics). How would the PhysicsServer API look like? I was writing something like this:

    virtual void joint_enable_feedback(RID p_joint, bool p_enabled) = 0;
    virtual Vector3 joint_get_applied_linear_impulse_body_a(RID p_joint) const = 0;
    virtual Vector3 joint_get_applied_torque_impulse_body_a(RID p_joint) const = 0;
    virtual Vector3 joint_get_applied_linear_impulse_body_b(RID p_joint) const = 0;
    virtual Vector3 joint_get_applied_torque_impulse_body_b(RID p_joint) const = 0;
Calinou commented 2 years ago

Question about the impulse feedback for joints (Which could also be implemented for GodotPhysics). How would the PhysicsServer API look like? I was writing something like this:*

The API looks reasonable to me, but I'm not well-versed in that part of the physics engine. I also wonder if the joint positions should be something like "start" and "end" instead of "a" and "b" – I don't know how they're called elsewhere in the engine.