-improved one-way collision handling in both dynamic and character bodies for 2D, fixes #1854

This commit is contained in:
Juan Linietsky 2015-05-10 19:24:09 -03:00
parent a2b8b92a6e
commit 32b1b472af
3 changed files with 19 additions and 4 deletions

View file

@ -265,7 +265,7 @@ bool BodyPair2DSW::setup(float p_step) {
} }
//faster to set than to check.. //faster to set than to check..
bool prev_collided=collided; //bool prev_collided=collided;
collided = CollisionSolver2DSW::solve(shape_A_ptr,xform_A,motion_A,shape_B_ptr,xform_B,motion_B,_add_contact,this,&sep_axis); collided = CollisionSolver2DSW::solve(shape_A_ptr,xform_A,motion_A,shape_B_ptr,xform_B,motion_B,_add_contact,this,&sep_axis);
if (!collided) { if (!collided) {
@ -282,12 +282,18 @@ bool BodyPair2DSW::setup(float p_step) {
collided=true; collided=true;
} }
if (!collided) if (!collided) {
oneway_disabled=false;
return false; return false;
}
} }
if (!prev_collided) { if (oneway_disabled)
return false;
//if (!prev_collided) {
{
if (A->is_using_one_way_collision()) { if (A->is_using_one_way_collision()) {
Vector2 direction = A->get_one_way_collision_direction(); Vector2 direction = A->get_one_way_collision_direction();
@ -309,6 +315,7 @@ bool BodyPair2DSW::setup(float p_step) {
if (!valid) { if (!valid) {
collided=false; collided=false;
oneway_disabled=true;
return false; return false;
} }
} }
@ -333,6 +340,7 @@ bool BodyPair2DSW::setup(float p_step) {
} }
if (!valid) { if (!valid) {
collided=false; collided=false;
oneway_disabled=true;
return false; return false;
} }
} }
@ -525,6 +533,7 @@ BodyPair2DSW::BodyPair2DSW(Body2DSW *p_A, int p_shape_A,Body2DSW *p_B, int p_sha
B->add_constraint(this,1); B->add_constraint(this,1);
contact_count=0; contact_count=0;
collided=false; collided=false;
oneway_disabled=false;
} }

View file

@ -76,6 +76,7 @@ class BodyPair2DSW : public Constraint2DSW {
Contact contacts[MAX_CONTACTS]; Contact contacts[MAX_CONTACTS];
int contact_count; int contact_count;
bool collided; bool collided;
bool oneway_disabled;
int cc; int cc;

View file

@ -655,7 +655,12 @@ bool Space2DSW::test_body_motion(Body2DSW *p_body,const Vector2&p_motion,float p
if (col_obj->get_type()==CollisionObject2DSW::TYPE_BODY) { if (col_obj->get_type()==CollisionObject2DSW::TYPE_BODY) {
const Body2DSW *body=static_cast<const Body2DSW*>(col_obj); const Body2DSW *body=static_cast<const Body2DSW*>(col_obj);
cbk.valid_dir=body->get_one_way_collision_direction();
Vector2 cdir = body->get_one_way_collision_direction();
if (cdir!=Vector2() && p_motion.dot(cdir)<0)
continue;
cbk.valid_dir=cdir;
cbk.valid_depth=body->get_one_way_collision_max_depth(); cbk.valid_depth=body->get_one_way_collision_max_depth();
} else { } else {
cbk.valid_dir=Vector2(); cbk.valid_dir=Vector2();