public static bool beginCollisionWithScenery(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; // The order of the arguments matches the order in the function name. arbiter.GetShapes(out shape1, out shape2); Jump jump = shape1.GetComponent <Jump>(); // if is jumping and hits a wall then continue the collision /*if (jump != null && jump.isJumping && GameObjectTools.isWallHit(arbiter)) * return true;*/ if (jump != null && GameObjectTools.isGrounded(arbiter)) { if (jump.foreverJump) { jump.forceJump(jump.foreverJumpVel); } // if it was jumping then reset jump behavior else if (jump.isJumping) { jump.stop(); } } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next frame. return(true); }
public static bool beginCollisionWithKoopaTroopa(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); KoopaTroopa koopa1 = shape1.GetComponent <KoopaTroopa>(); KoopaTroopa koopa2 = shape2.GetComponent <KoopaTroopa>(); bool hidden1 = koopa1._hide.isHidden(); bool hidden2 = koopa2._hide.isHidden(); bool bouncing1 = koopa1.bounce.isBouncing(); bool bouncing2 = koopa2.bounce.isBouncing(); // avoid koopa1 pushes hidden koopa2 Chase chase = shape1.GetComponent <Chase>(); if (chase != null && chase.isChasing()) { chase.stopChasing(); chase.enableOperateWhenOutOfSensor(); } // avoid koopa2 pushes hidden koopa1 chase = shape2.GetComponent <Chase>(); if (chase != null && chase.isChasing()) { chase.stopChasing(); chase.enableOperateWhenOutOfSensor(); } // is koopa above the other koopa? if (GameObjectTools.isGrounded(arbiter)) { if (!hidden1) { koopa1.jump.forceJump(koopa1.jumpSpeed); } else { koopa2.jump.forceJump(koopa1.jumpSpeed); } // NOTE: I assume here the isGrounded() works as expected return(false); // avoid the collision to continue since this frame } // kills koopa 2 else if (bouncing1 && !hidden2 && !bouncing2) { //koopa2.die(); koopa2.hide(); } // kills koopa 1 else if (bouncing2 && !hidden1 && !bouncing1) { //koopa1.die(); koopa1.hide(); } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next frame. return(true); }
public static bool beginCollisionWithKoopaTroopa(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); KoopaTroopa koopa1 = shape1.getOwnComponent <KoopaTroopa>(); KoopaTroopa koopa2 = shape2.getOwnComponent <KoopaTroopa>(); bool hidden1 = koopa1._hide.isHidden(); bool hidden2 = koopa2._hide.isHidden(); bool bouncing1 = koopa1.bounce.isBouncing(); bool bouncing2 = koopa2.bounce.isBouncing(); // avoid koopa1 pushes hidden koopa2 Chase chase1 = shape1.GetComponent <Chase>(); if (chase1 != null && chase1.isChasing()) { chase1.stop(); chase1.enableOperateWhenOutOfSensor(); } // avoid koopa2 pushes hidden koopa1 Chase chase2 = shape2.GetComponent <Chase>(); if (chase2 != null && chase2.isChasing()) { chase2.stop(); chase2.enableOperateWhenOutOfSensor(); } // is koopa1 above the koopa2? if (GameObjectTools.isGrounded(arbiter)) { if (!hidden1 && koopa1.jump.isJumping()) { koopa1.jump.forceJump(koopa1.jumpSpeed); } else if (hidden1 && koopa2.jump.isJumping()) { koopa2.jump.forceJump(koopa1.jumpSpeed); } return(false); // avoid the collision since this frame } // hide koopa 2 else if (bouncing1 && !hidden2 && !bouncing2) { koopa2.hide(); } // hide koopa 1 else if (bouncing2 && !hidden1 && !bouncing1) { //koopa1.die(); koopa1.hide(); } // Returning false from a begin callback means to ignore the collision response for these two colliding shapes // until they separate. Also for current frame. Ignore() does the same but next fixed step. return(true); }