Godot Version
Godot Engine v4.2.2.stable.official.15073afe3
Question
I’m trying to access the impulse vector, when two RigidBody2D objects colloid.
For this I wrote this in my RigidBody2D gdscript:
The problem is, when there’s a collision and I see the print “APPLIED IMPULSE”, I always get 0 for state.get_contact_impulse(0)
why is that? I’m expecting it to be printed for each colliding object and display the impulse applied to them because of the collision.
There are only two objects of type RigidBody2D, names pen_fighter, and pen_fighter2. I’m attaching the log I see for this code when these two objects colloid:
state.get_contact_count() = 1
get_colliding_bodies =[]
state.get_contact_count() = 1
get_colliding_bodies =[pen_fighter2:<RigidBody2D#24930944216>]
state.get_contact_count() = 0
APPLIED IMPULSE = (0, 0)
get_colliding_bodies =[pen_fighter:<RigidBody2D#24880612557>]
state.get_contact_count() = 0
APPLIED IMPULSE = (0, 0)
get_colliding_bodies =[]
I think it could be related to this bug:
opened 01:30AM - 18 Feb 23 UTC
bug
topic:physics
### Godot version
v4.0.rc2.official [d2699dc7a]
### System information
Endeav… ourOS, Vulkan
### Issue description
Calling the `get_contact_impulse()` method on the PhysicsDirectState3D object provided in the `_integrate_forces()` method of `RigidBody3D` returns `Vector3.ZERO` for contacts that were created in the current frame. I would expect this method to return the impulse applied to the rigidbody by the contact, even during the first frame.
This becomes an issue particularly with bouncy objects as they often only have one frame of contact which results in no impulse being reported at all.
I dug a bit in the physics code and it seems that the contacts of a rigidbody are not updated after `pre_solve` in `GodotBodyPair3D` ran which seems suspicious.
### Steps to reproduce
1. set up a scene with a rigidbody with a collider and something it can collide with (I tested both rigidbodies and staticbodies for this)
2. Turn on `contact_monitor` and set `max_contacts_reported` to a reasonable value
3. Add a script to the rigidbody that implements `_integrate_forces()` and call `state.get_contact_impulse()`, for example print all impulses for all contacts
4. Observe that during the first frame after a new contact is created a zero vector is returned. This is more obvious when a physics material with bounciness 1.0 is added to the rigidbody.
### Minimal reproduction project
[impulse_test.zip](https://github.com/godotengine/godot/files/10772643/impulse_test.zip)
I read up some documentation and saw changing below value could help:
physics-tick-per-second from 60 to 240
max physics steps per second from 8 to 32
I was able to see some impuls values. But those values are not as I expected.
Hi @amityadav381 , did you manage to figure out this topic?
Hi @dooferino I changed my solution to not include this approach.
here’s the complete game I made.