Skip to content

Commit c227126

Browse files
committed
Merge pull request #109820 from groud/fix_one_way_collision_tilemaplayer
Fix one-way-collision polygons being merged despite being on different Y-origins in TileMapLayer
2 parents a49cf24 + e992c7d commit c227126

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

scene/2d/tile_map_layer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ void TileMapLayer::_physics_update(bool p_force_cleanup) {
841841
physics_body_key.angular_velocity = angular_velocity;
842842
physics_body_key.one_way_collision = tile_data->is_collision_polygon_one_way(tile_set_physics_layer, polygon_index);
843843
physics_body_key.one_way_collision_margin = tile_data->get_collision_polygon_one_way_margin(tile_set_physics_layer, polygon_index);
844+
physics_body_key.y_origin = map_to_local(cell_data.coords).y;
844845

845846
if (!physics_quadrant->bodies.has(physics_body_key)) {
846847
RID body = ps->body_create();

scene/2d/tile_map_layer.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,20 @@ class PhysicsQuadrant : public RefCounted {
243243
int physics_layer = 0;
244244
Vector2 linear_velocity;
245245
real_t angular_velocity = 0.0;
246+
246247
bool one_way_collision = false;
247248
real_t one_way_collision_margin = 0.0;
248249

250+
int64_t y_origin = 0; // This is only used if one_way_collision is on, to avoid merging polygons vertically in that case.
251+
249252
bool operator<(const PhysicsBodyKey &p_other) const {
250253
if (physics_layer == p_other.physics_layer) {
251254
if (linear_velocity == p_other.linear_velocity) {
252255
if (angular_velocity == p_other.angular_velocity) {
253256
if (one_way_collision == p_other.one_way_collision) {
257+
if (one_way_collision && y_origin != p_other.y_origin) {
258+
return y_origin < p_other.y_origin;
259+
}
254260
return one_way_collision_margin < p_other.one_way_collision_margin;
255261
}
256262
return one_way_collision < p_other.one_way_collision;
@@ -270,7 +276,8 @@ class PhysicsQuadrant : public RefCounted {
270276
linear_velocity == p_other.linear_velocity &&
271277
angular_velocity == p_other.angular_velocity &&
272278
one_way_collision == p_other.one_way_collision &&
273-
one_way_collision_margin == p_other.one_way_collision_margin;
279+
one_way_collision_margin == p_other.one_way_collision_margin &&
280+
(!one_way_collision || y_origin == p_other.y_origin);
274281
}
275282
};
276283

@@ -280,6 +287,9 @@ class PhysicsQuadrant : public RefCounted {
280287
h = hash_murmur3_one_real(p_hash.linear_velocity.x);
281288
h = hash_murmur3_one_real(p_hash.linear_velocity.y, h);
282289
h = hash_murmur3_one_real(p_hash.angular_velocity, h);
290+
if (p_hash.one_way_collision) {
291+
h = hash_murmur3_one_32(p_hash.y_origin, h);
292+
}
283293
return h;
284294
}
285295
};

0 commit comments

Comments
 (0)