summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikael Hermansson <mikael@hermansson.io>2024-02-06 14:23:08 +0100
committerMikael Hermansson <mikael@hermansson.io>2024-02-06 14:29:43 +0100
commitf2d615cdc7bbb52ee2462eff824cfd559343a282 (patch)
tree4863fd9bdc8be43ed37537e89eacffe0df4c3168
parentd3352813ea44447bfbf135efdec23acc4d1d3f89 (diff)
downloadredot-engine-f2d615cdc7bbb52ee2462eff824cfd559343a282.tar.gz
Fix contact count sometimes being incorrect in `_process`
-rw-r--r--scene/2d/physics_body_2d.cpp6
-rw-r--r--scene/2d/physics_body_2d.h1
-rw-r--r--scene/3d/physics_body_3d.cpp6
-rw-r--r--scene/3d/physics_body_3d.h1
4 files changed, 8 insertions, 6 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index af9008f452..92af3fa3f0 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -446,6 +446,8 @@ void RigidBody2D::_sync_body_state(PhysicsDirectBodyState2D *p_state) {
linear_velocity = p_state->get_linear_velocity();
angular_velocity = p_state->get_angular_velocity();
+ contact_count = p_state->get_contact_count();
+
if (sleeping != p_state->is_sleeping()) {
sleeping = p_state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
@@ -797,9 +799,7 @@ int RigidBody2D::get_max_contacts_reported() const {
}
int RigidBody2D::get_contact_count() const {
- PhysicsDirectBodyState2D *bs = PhysicsServer2D::get_singleton()->body_get_direct_state(get_rid());
- ERR_FAIL_NULL_V(bs, 0);
- return bs->get_contact_count();
+ return contact_count;
}
void RigidBody2D::apply_central_impulse(const Vector2 &p_impulse) {
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 62636b02f4..88161e284a 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -164,6 +164,7 @@ private:
bool sleeping = false;
int max_contacts_reported = 0;
+ int contact_count = 0;
bool custom_integrator = false;
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 7d08d767c7..67a7f76d7d 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -502,6 +502,8 @@ void RigidBody3D::_sync_body_state(PhysicsDirectBodyState3D *p_state) {
inverse_inertia_tensor = p_state->get_inverse_inertia_tensor();
+ contact_count = p_state->get_contact_count();
+
if (sleeping != p_state->is_sleeping()) {
sleeping = p_state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
@@ -877,9 +879,7 @@ int RigidBody3D::get_max_contacts_reported() const {
}
int RigidBody3D::get_contact_count() const {
- PhysicsDirectBodyState3D *bs = PhysicsServer3D::get_singleton()->body_get_direct_state(get_rid());
- ERR_FAIL_NULL_V(bs, 0);
- return bs->get_contact_count();
+ return contact_count;
}
void RigidBody3D::apply_central_impulse(const Vector3 &p_impulse) {
diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h
index e8373d5907..b84b7c4f02 100644
--- a/scene/3d/physics_body_3d.h
+++ b/scene/3d/physics_body_3d.h
@@ -177,6 +177,7 @@ private:
bool ccd = false;
int max_contacts_reported = 0;
+ int contact_count = 0;
bool custom_integrator = false;