godotengine / godot-proposals

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

Improve the data provided by `PhysicsDirectSpaceState.get_rest_info()` #9341

Open yosoyfreeman opened 3 months ago

yosoyfreeman commented 3 months ago

Describe the project you are working on

An sliding algorithm.

Describe the problem or limitation you are having in your project

In order to implement a reliable work-flow for kinematic bodies i need to gather information about all the collision normals touching the shape + an margin. This can not be achieved right now with a simple test, because get_rest_info will only provide the nearest one. The solution is to create a whole shapeCast node (Intended for movement) and provide it a motion vector of zero. This adds unnecessary complexity to a check that is often frequently needed in order to implement proper collision response and depenetration for all kind of purposes. Also, this solution is not obvious to the end user, as they will look at the PhysicsDirectSpaceState documentation page, which is supposed to provide the most complete data about the state of a physics body.

It also lacks the margin that ShapeCast node provides, which helps detecting geometry very near to the shape and react to it.

Both of this features are already implemented, but they are only available on ShapeCast node.

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

The Godot source code is still a bit confusing to me, but the ShapeCast node is providing this information already, so suspect there is already a way of gathering this data and adding this margin to the check on the code, just not exposed to the user.

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

No. Collision data is extremely complex to gather from scratch.

Just in case: Doing get_rest_info, add that body to the exceptions list and do it again is not equivalent. If the collisions are against the same body, you will get only one and there still is no margin.

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

Improving the usability and robustness of the collision data is core functionality of a 3D engine, as everything that interacts in a physical way relies on this methods.

sinewavey commented 1 month ago

Apologies if this is off-topic, but I'm also working on a slide algorithm. While you're far ahead of me, I'm curious about the 'solution involving a shapecast' right now. I've been using cast motion -> rest info and have issues though it is close it is still unsatisfactory. Would you provide more details about this?

yosoyfreeman commented 1 month ago

Hi! When i made this post i was referring to the fact that a shape cast node would do the trick, but i was wrong.

The shapeCast node does not really provide enough information either. It will only give you one contact per object, so, unless every triangle is a different object, as far as i know, this is just not possible for the end user.

sinewavey commented 1 month ago

Unfortunate. Thanks for the investigation anyway. As someone making a Quake-like, I've been fiddling it for months now. I hope we can find a path forward soon for Godot (and perhaps Jolt, though I know there wasn't much success over there either from the GH issues).

If you would like to talk further sometime about things I would really like to perhaps see if we can figure anything else out, though GitHub is a bit awkward to communicate on sometimes. Please let me know if you'd be interested at all!