-Re-added margins in one way collision (made in a more user friendly way than in Godot 2.1), fixes #23860
-Fixed potential bug in OWC (i dont think anyone had it but..)
This commit is contained in:
parent
541422a4a2
commit
d8b702b566
16 changed files with 131 additions and 11 deletions
|
|
@ -40,6 +40,7 @@ void CollisionObject2DSW::add_shape(Shape2DSW *p_shape, const Transform2D &p_tra
|
|||
s.bpid = 0; //needs update
|
||||
s.disabled = false;
|
||||
s.one_way_collision = false;
|
||||
s.one_way_collision_margin = 0;
|
||||
shapes.push_back(s);
|
||||
p_shape->add_owner(this);
|
||||
_update_shapes();
|
||||
|
|
|
|||
|
|
@ -62,9 +62,11 @@ private:
|
|||
Variant metadata;
|
||||
bool disabled;
|
||||
bool one_way_collision;
|
||||
float one_way_collision_margin;
|
||||
Shape() {
|
||||
disabled = false;
|
||||
one_way_collision = false;
|
||||
one_way_collision_margin = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -150,15 +152,21 @@ public:
|
|||
return shapes[p_idx].disabled;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void set_shape_as_one_way_collision(int p_idx, bool p_one_way_collision) {
|
||||
_FORCE_INLINE_ void set_shape_as_one_way_collision(int p_idx, bool p_one_way_collision, float p_margin) {
|
||||
CRASH_BAD_INDEX(p_idx, shapes.size());
|
||||
shapes.write[p_idx].one_way_collision = p_one_way_collision;
|
||||
shapes.write[p_idx].one_way_collision_margin = p_margin;
|
||||
}
|
||||
_FORCE_INLINE_ bool is_shape_set_as_one_way_collision(int p_idx) const {
|
||||
CRASH_BAD_INDEX(p_idx, shapes.size());
|
||||
return shapes[p_idx].one_way_collision;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ float get_shape_one_way_collision_margin(int p_idx) const {
|
||||
CRASH_BAD_INDEX(p_idx, shapes.size());
|
||||
return shapes[p_idx].one_way_collision_margin;
|
||||
}
|
||||
|
||||
void set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; }
|
||||
_FORCE_INLINE_ uint32_t get_collision_mask() const { return collision_mask; }
|
||||
|
||||
|
|
|
|||
|
|
@ -209,12 +209,14 @@ void Physics2DServerSW::_shape_col_cbk(const Vector2 &p_point_A, const Vector2 &
|
|||
return;
|
||||
cbk->ptr[min_depth_idx * 2 + 0] = p_point_A;
|
||||
cbk->ptr[min_depth_idx * 2 + 1] = p_point_B;
|
||||
cbk->passed++;
|
||||
|
||||
} else {
|
||||
|
||||
cbk->ptr[cbk->amount * 2 + 0] = p_point_A;
|
||||
cbk->ptr[cbk->amount * 2 + 1] = p_point_B;
|
||||
cbk->amount++;
|
||||
cbk->passed++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,6 +235,7 @@ bool Physics2DServerSW::shape_collide(RID p_shape_A, const Transform2D &p_xform_
|
|||
CollCbkData cbk;
|
||||
cbk.max = p_result_max;
|
||||
cbk.amount = 0;
|
||||
cbk.passed = 0;
|
||||
cbk.ptr = r_results;
|
||||
|
||||
bool res = CollisionSolver2DSW::solve(shape_A, p_xform_A, p_motion_A, shape_B, p_xform_B, p_motion_B, _shape_col_cbk, &cbk);
|
||||
|
|
@ -740,14 +743,14 @@ void Physics2DServerSW::body_set_shape_disabled(RID p_body, int p_shape_idx, boo
|
|||
|
||||
body->set_shape_as_disabled(p_shape_idx, p_disabled);
|
||||
}
|
||||
void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable) {
|
||||
void Physics2DServerSW::body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, float p_margin) {
|
||||
|
||||
Body2DSW *body = body_owner.get(p_body);
|
||||
ERR_FAIL_COND(!body);
|
||||
|
||||
ERR_FAIL_INDEX(p_shape_idx, body->get_shape_count());
|
||||
|
||||
body->set_shape_as_one_way_collision(p_shape_idx, p_enable);
|
||||
body->set_shape_as_one_way_collision(p_shape_idx, p_enable, p_margin);
|
||||
}
|
||||
|
||||
void Physics2DServerSW::body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) {
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ public:
|
|||
real_t valid_depth;
|
||||
int max;
|
||||
int amount;
|
||||
int passed;
|
||||
int invalid_by_dir;
|
||||
Vector2 *ptr;
|
||||
};
|
||||
|
|
@ -188,7 +189,7 @@ public:
|
|||
virtual void body_clear_shapes(RID p_body);
|
||||
|
||||
virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled);
|
||||
virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable);
|
||||
virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape_idx, bool p_enable, float p_margin);
|
||||
|
||||
virtual void body_attach_object_instance_id(RID p_body, uint32_t p_ID);
|
||||
virtual uint32_t body_get_object_instance_id(RID p_body) const;
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ public:
|
|||
FUNC2RC(RID, body_get_shape, RID, int);
|
||||
|
||||
FUNC3(body_set_shape_disabled, RID, int, bool);
|
||||
FUNC3(body_set_shape_as_one_way_collision, RID, int, bool);
|
||||
FUNC4(body_set_shape_as_one_way_collision, RID, int, bool, float);
|
||||
|
||||
FUNC2(body_remove_shape, RID, int);
|
||||
FUNC1(body_clear_shapes, RID);
|
||||
|
|
|
|||
|
|
@ -328,6 +328,7 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Transform2D &
|
|||
Physics2DServerSW::CollCbkData cbk;
|
||||
cbk.max = p_result_max;
|
||||
cbk.amount = 0;
|
||||
cbk.passed = 0;
|
||||
cbk.ptr = r_results;
|
||||
CollisionSolver2DSW::CallbackResult cbkres = NULL;
|
||||
|
||||
|
|
@ -573,6 +574,7 @@ int Space2DSW::test_body_ray_separation(Body2DSW *p_body, const Transform2D &p_t
|
|||
int shape_idx = intersection_query_subindex_results[i];
|
||||
|
||||
cbk.amount = 0;
|
||||
cbk.passed = 0;
|
||||
cbk.ptr = sr;
|
||||
cbk.invalid_by_dir = 0;
|
||||
|
||||
|
|
@ -720,6 +722,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
|
|||
Physics2DServerSW::CollCbkData cbk;
|
||||
cbk.max = max_results;
|
||||
cbk.amount = 0;
|
||||
cbk.passed = 0;
|
||||
cbk.ptr = sr;
|
||||
cbk.invalid_by_dir = 0;
|
||||
excluded_shape_pair_count = 0; //last step is the one valid
|
||||
|
|
@ -759,7 +762,9 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
|
|||
|
||||
cbk.valid_dir = col_obj_shape_xform.get_axis(1).normalized();
|
||||
|
||||
cbk.valid_depth = p_margin; //only valid depth is the collision margin
|
||||
float owc_margin = col_obj->get_shape_one_way_collision_margin(shape_idx);
|
||||
print_line("margin: " + rtos(owc_margin));
|
||||
cbk.valid_depth = MAX(owc_margin, p_margin); //user specified, but never less than actual margin or it wont work
|
||||
cbk.invalid_by_dir = 0;
|
||||
|
||||
if (col_obj->get_type() == CollisionObject2DSW::TYPE_BODY) {
|
||||
|
|
@ -780,12 +785,12 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
|
|||
cbk.invalid_by_dir = 0;
|
||||
}
|
||||
|
||||
int current_collisions = cbk.amount;
|
||||
int current_passed = cbk.passed; //save how many points passed collision
|
||||
bool did_collide = false;
|
||||
|
||||
Shape2DSW *against_shape = col_obj->get_shape(shape_idx);
|
||||
if (CollisionSolver2DSW::solve(body_shape, body_shape_xform, Vector2(), against_shape, col_obj_shape_xform, Vector2(), cbkres, cbkptr, NULL, separation_margin)) {
|
||||
did_collide = cbk.amount > current_collisions;
|
||||
did_collide = cbk.passed > current_passed; //more passed, so collision actually existed
|
||||
}
|
||||
|
||||
if (!did_collide && cbk.invalid_by_dir > 0) {
|
||||
|
|
@ -933,6 +938,7 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body, const Transform2D &p_from, co
|
|||
Physics2DServerSW::CollCbkData cbk;
|
||||
cbk.max = 1;
|
||||
cbk.amount = 0;
|
||||
cbk.passed = 0;
|
||||
cbk.ptr = cd;
|
||||
cbk.valid_dir = col_obj_shape_xform.get_axis(1).normalized();
|
||||
|
||||
|
|
|
|||
|
|
@ -398,7 +398,7 @@ public:
|
|||
virtual Variant body_get_shape_metadata(RID p_body, int p_shape_idx) const = 0;
|
||||
|
||||
virtual void body_set_shape_disabled(RID p_body, int p_shape, bool p_disabled) = 0;
|
||||
virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled) = 0;
|
||||
virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled, float p_margin = 0) = 0;
|
||||
|
||||
virtual void body_remove_shape(RID p_body, int p_shape_idx) = 0;
|
||||
virtual void body_clear_shapes(RID p_body) = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue