diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-11 11:02:50 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-11 11:02:50 +0200 |
| commit | e911fcda1b2e4c2f8524d5dc14f45a27f94d51b3 (patch) | |
| tree | af9040cb3eaa658b7a3b29e33087334b08e75024 | |
| parent | 58f8a227b94fbd164ca1f6657980060a41aec940 (diff) | |
| parent | 3590d49c7079fc2456b203a52edc3881236fbae5 (diff) | |
| download | redot-engine-e911fcda1b2e4c2f8524d5dc14f45a27f94d51b3.tar.gz | |
Merge pull request #90503 from rburing/gridmap_has_it_rough
GridMap: Fix `physics_material` property
| -rw-r--r-- | modules/gridmap/grid_map.cpp | 19 | ||||
| -rw-r--r-- | modules/gridmap/grid_map.h | 1 |
2 files changed, 17 insertions, 3 deletions
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index fb449a67f8..25519c6e3c 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -195,7 +195,7 @@ real_t GridMap::get_collision_priority() const { void GridMap::set_physics_material(Ref<PhysicsMaterial> p_material) { physics_material = p_material; - _recreate_octant_data(); + _update_physics_bodies_characteristics(); } Ref<PhysicsMaterial> GridMap::get_physics_material() const { @@ -370,8 +370,8 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) { PhysicsServer3D::get_singleton()->body_set_collision_mask(g->static_body, collision_mask); PhysicsServer3D::get_singleton()->body_set_collision_priority(g->static_body, collision_priority); if (physics_material.is_valid()) { - PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->get_friction()); - PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->get_bounce()); + PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->computed_friction()); + PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->computed_bounce()); } SceneTree *st = SceneTree::get_singleton(); @@ -748,6 +748,19 @@ void GridMap::_update_physics_bodies_collision_properties() { } } +void GridMap::_update_physics_bodies_characteristics() { + real_t friction = 1.0; + real_t bounce = 0.0; + if (physics_material.is_valid()) { + friction = physics_material->computed_friction(); + bounce = physics_material->computed_bounce(); + } + for (const KeyValue<OctantKey, Octant *> &E : octant_map) { + PhysicsServer3D::get_singleton()->body_set_param(E.value->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, friction); + PhysicsServer3D::get_singleton()->body_set_param(E.value->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, bounce); + } +} + void GridMap::_octant_enter_world(const OctantKey &p_key) { ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 7398a540de..1f006f661a 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -187,6 +187,7 @@ class GridMap : public Node3D { } void _update_physics_bodies_collision_properties(); + void _update_physics_bodies_characteristics(); void _octant_enter_world(const OctantKey &p_key); void _octant_exit_world(const OctantKey &p_key); bool _octant_update(const OctantKey &p_key); |
