godotengine / godot-proposals

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

Expose `m_raycastInfo` in VehicleWheel3D to scripting #10106

Open TestSubject06 opened 1 month ago

TestSubject06 commented 1 month ago

Describe the project you are working on

I'm working on a vehicular combat game with lots of verticality. The vehicles are in the air quite a bit, and the suspensions are taxed a lot.

Describe the problem or limitation you are having in your project

The current implementation of the VehicleBody3D and VehicleWheel3D makes it impossible to collect the raycast information from the suspension. I have no good way to place the tire marks on the ground without being able to collect the collision point and normal from the wheels.

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

Exposing the raycast information that's already present in the wheel will make it easy to implement this feature, as I will know the collision point and normal that the wheel has detected.

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

Either a collection of methods like get_contact_normal() or get_contact_position(), or simply exposing the entire m_raycastInfo struct to scripting will work fine. The data is already there and maintained as seen in https://github.com/godotengine/godot/blob/master/scene/3d/physics/vehicle_body_3d.h. It should be trivial for a C++ engineer to go in and expose these.

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

The current workaround is to create a second raycast for each of the wheels to re-do the work, or attempt to reverse the collision point (but crucially not the normal) from the wheel's rendered position.

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

I'm not aware of an asset library or addon that can reach into the C++ code and expose properties like this.

TestSubject06 commented 1 month ago

Added a possible implementation here: https://github.com/godotengine/godot/pull/93900