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

New contact velocity method on PhysicsDirectBodyState3D #4184

Closed
tgift opened this issue Mar 7, 2022 · 2 comments · Fixed by godotengine/godot#58880
Closed

New contact velocity method on PhysicsDirectBodyState3D #4184

tgift opened this issue Mar 7, 2022 · 2 comments · Fixed by godotengine/godot#58880

Comments

@tgift
Copy link

tgift commented Mar 7, 2022

Describe the project you are working on

VR Game development. Just a small test at present.

Describe the problem or limitation you are having in your project

I'd like to compute the impact velocity of a contact. Direct queries to the PhysicsDirectBodyState3D object from _on_body_entered() results in values that don't reflect the velocities at the time of impact, and the array of contacts on the direct body state does not include enough information to perform the calculation. The contact array includes the contact position of the state and collision bodies, but only the velocity of the state body. This velocity is obtained through the, what I believe is mis-named, "get_contact_collider_velocity_at_position" method.

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

I propose changing "get_contact_collider_velocity_at_position()" to return the velocity of the collider, and to add a new method "get_contact_local_velocity_at_position()" to return the state body's velocity.

This would allow the impact velocity, or speed, to be computed as follows:

var state = PhysicsServer3D.body_get_direct_state(self)
...
var vel1 = state.get_contact_local_velocity_at_position(i)
var vel2 = state.get_contact_collider_velocity_at_position(i)
vat normal = state.get_contact_local_normal()
var contact_speed = normal.dot(vel1 - vel2)

This would break anyone relying on the current behavior of "get_contact_colllider_velocity_at_position()". They would have to switch to the new method.

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

I've submitted a pull request #58880 that includes this change as well as a fix for the "get_contact_local_position()" and "get_contact_collider_position()" methods. Details explained there.

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

I know of no other way to obtain or compute the contact velocity at time of impact.

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

Don't think this can be added otherwise.

@Calinou Calinou added this to the 4.0 milestone Mar 7, 2022
@tgift
Copy link
Author

tgift commented Mar 7, 2022

I was just updating the documentation on my pull_request and noticed that the description for "get_contact_collider_velocity_at_position()" states that it is returning the collider's velocity, not the state body's, so this proposed change would bring the function into alignment with it's documentation.

@Zireael07
Copy link

Thanks for making this proposal! I thought I had one, but no. I need a way to know the velocity at the moment of impact to deform my car meshes ;)

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

Successfully merging a pull request may close this issue.

5 participants