You can make every object compute its personal impulse utilizing linear momentum change. This answer makes use of Indicators and tracks state variables manually. It really works for linear momentum solely, however you’ll be able to prolong it to incorporate angular momentum too.
Add a script to a inflexible physique. A variable will retailer the thing’s linear velocity earlier than updates at every physics body:
extends RigidBody3D
var prev_velocity: Vector3
func _physics_process(_delta: float) -> void:
prev_velocity = linear_velocity
To configure the inflexible physique to emit indicators when colliding with one other physique, from the Inspector, set Contact Monitor to True and Max Contacts Reported to a price bigger than 0 (I set it to 4 simply in case). Relying on the thing form, you could wish to allow Steady CD too.
Now, join the body_entered
Sign of the inflexible physique to its personal Script in a brand new Receiver Technique. This methodology can be emitted routinely after the physics engine has resolved all collisions. Subsequently, the inflexible physique will work out what impulse was utilized to show its earlier velocity into the present one:
func _on_body_entered(physique: Node) -> void:
var impulse = mass * (linear_velocity - last_velocity)
print(title + " collide with " + physique.title + " pressure " + str(impulse.size()))
The above means: physics engine utilized a pressure of impulse
magnitude for physics course of’ delta
seconds to the thing on account of resolving all collision pairs, inflicting its linear velocity to change from prev_velocity
(earlier body) to linear_velocity
(present body).
The above snippet works when the thing collides each with static our bodies and different inflexible our bodies. RB pairs will compute impulses that can clarify their remaining velocities.
If “unusual numbers” begin showing, this is because of the truth that I did not take angular momentum under consideration, so whole momentum remains to be there within the Physics Server however wasn’t computed in my customized script.