How to measure impact between two Physics bodys

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rayosdev
:warning: Old Version Published before Godot 3 was released.

I’m trying to measure the force applied to one RigiedBody2D to another. Is there a function for this or is it just a question of vector math? in witch case a hint about what that type of math is called would be apreaciate

:bust_in_silhouette: Reply From: avencherus

As far as I can tell there aren’t any queries in the script to directly get the impact values from the solvers.

If you’re wondering about the math, RigidBodies generally use inelastic collisions formulas, where the masses exchange velocities along a collision normal. There’s a so so article on it here at Gamasutra:

A possible solution to your problem that may be worth testing is just monitoring the length (magnitude) of the velocity vector of your chosen object. After a collision compare the difference in length. If it loses force it’s velocity magnitude should shrink, if it gains force, then the magnitude will grow.

Depending on the frame timing, the difference between the current and previous velocity magnitude might answer that question.

Physics2DDirectBodyState may help to get some information for calculations with get_contact_collider_velocity_at_pos

There is the Physics2DTestMotionResult too but I don’t know how it is used.

eons | 2017-01-23 10:33

Just one correction: that’s called an elastic collision. You get an inelastic collision when the colliding objects deform and stay deformed like bags of sand.

Warlaan | 2017-01-26 10:05