godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.05k stars 65 forks source link

Checking if Points are within a given CollisionShape #9636

Open AdeptusForge opened 2 weeks ago

AdeptusForge commented 2 weeks ago

Describe the project you are working on

Implementing an RRT* algorithm for my portfolio. One of the most integral steps is generating random points in a given space, then attaching them to the closest point on the tree.

Describe the problem or limitation you are having in your project

Without the ability to check if a point is within any collider, it slows down calculation during point generation and makes the entire code more cumbersome, as now I have to manually track the positions of every blocking element in the environment.

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

Having an API call to check points against colliders solves the point generation problem, and allows for further optimization with a partitioning heuristic.

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

The code fundamentally already exists in the engine in godotshape2d/3d, it just needs to be migrated over and given API calls within the engine. I've already begun a quick pull request for the matter for godotshape2d's, you can see the basic implementation there.

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

It can be worked around by doing the math by hand for each collider, but that'd just be copying boilerplate code.

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

This functionality is tied intrinsically to the collisionshape system; it'd be far more work to turn it into an add-on than to simply modify the API under the hood to allow its usage.

KoBeWi commented 2 weeks ago

It can be also worked around by using Area2Ds and checking for overlaps.

Jesusemora commented 2 weeks ago

We have servers... https://docs.godotengine.org/en/4.2/classes/class_physicsdirectspacestate3d.html#class-physicsdirectspacestate3d-method-intersect-shape