Skip to content

Commit e911fcd

Browse files
committed
Merge pull request godotengine#90503 from rburing/gridmap_has_it_rough
GridMap: Fix `physics_material` property
2 parents 58f8a22 + 3590d49 commit e911fcd

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

modules/gridmap/grid_map.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ real_t GridMap::get_collision_priority() const {
195195

196196
void GridMap::set_physics_material(Ref<PhysicsMaterial> p_material) {
197197
physics_material = p_material;
198-
_recreate_octant_data();
198+
_update_physics_bodies_characteristics();
199199
}
200200

201201
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) {
370370
PhysicsServer3D::get_singleton()->body_set_collision_mask(g->static_body, collision_mask);
371371
PhysicsServer3D::get_singleton()->body_set_collision_priority(g->static_body, collision_priority);
372372
if (physics_material.is_valid()) {
373-
PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->get_friction());
374-
PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->get_bounce());
373+
PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->computed_friction());
374+
PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->computed_bounce());
375375
}
376376
SceneTree *st = SceneTree::get_singleton();
377377

@@ -748,6 +748,19 @@ void GridMap::_update_physics_bodies_collision_properties() {
748748
}
749749
}
750750

751+
void GridMap::_update_physics_bodies_characteristics() {
752+
real_t friction = 1.0;
753+
real_t bounce = 0.0;
754+
if (physics_material.is_valid()) {
755+
friction = physics_material->computed_friction();
756+
bounce = physics_material->computed_bounce();
757+
}
758+
for (const KeyValue<OctantKey, Octant *> &E : octant_map) {
759+
PhysicsServer3D::get_singleton()->body_set_param(E.value->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, friction);
760+
PhysicsServer3D::get_singleton()->body_set_param(E.value->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, bounce);
761+
}
762+
}
763+
751764
void GridMap::_octant_enter_world(const OctantKey &p_key) {
752765
ERR_FAIL_COND(!octant_map.has(p_key));
753766
Octant &g = *octant_map[p_key];

modules/gridmap/grid_map.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class GridMap : public Node3D {
187187
}
188188

189189
void _update_physics_bodies_collision_properties();
190+
void _update_physics_bodies_characteristics();
190191
void _octant_enter_world(const OctantKey &p_key);
191192
void _octant_exit_world(const OctantKey &p_key);
192193
bool _octant_update(const OctantKey &p_key);

0 commit comments

Comments
 (0)