Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new method to PhysicsDirectSpaceState for getting shape rest info from multiple contacts #11609

Open
DinkeyKing opened this issue Jan 19, 2025 · 0 comments

Comments

@DinkeyKing
Copy link

DinkeyKing commented Jan 19, 2025

Describe the project you are working on

I'm working on a 3D kinematic/virtual character body implementation. These types of bodies are simulated using collision checks outside of the dynamic physics simulation, hence the name virtual.

Describe the problem or limitation you are having in your project

I often just need to get the intersections of the shape at a given position, no motion involved (ex.: What is the character currently touching?). While PhysicsServer3D.body_test_motion can be used for moving the shape and getting the full shape rest info at the unsafe fraction, it can not be used for a stationary collision check, because the the shape is moved away from collisions in the recovery phase, so it's very inaccurate, and also is a huge overhead because it involves a large number of collision checks.

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

Ideally, PhysicsDirectSpaceState.get_rest_info should just be able to give out the complete rest information, but I understand that it would break compatibility, so I propose a new method instead. Adding this new method will allow getting all contact infos of a shape's intersections in a given space. The method should be available in both 3D and 2D.

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

I already started implementing it in this PR: godotengine/godot/pull/101676.

The method functions like PhysicsDirectSpaceState.get_rest_info, but allows for multiple results.
The method's second parameter allows for limiting the number of results.
It returns an array of dictionaries, the dictionaries contain the same data as the one returned by PhysicsDirectSpaceState.get_rest_info.

A code snippet from my test project:

var space_state := get_world_3d().direct_space_state

var params := PhysicsShapeQueryParameters3D.new()
params.transform = global_transform
params.shape = box_shape

var results : Array[Dictionary] = space_state.get_complete_rest_info(params, 2)

for r : Dictionary in results:
	create_sphere_at_point(r["point"], 0.1)
	print(r["normal"])

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

This is a core functionality of a 3D and 2D physics engine, no workaround possible.

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

This is a core functionality of a 3D and 2D physics engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants