@@ -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