public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); KoopaTroopa koopa = shape1.getOwnComponent <KoopaTroopa>(); Player player = shape2.getOwnComponent <Player>(); if (player.isDying()) { arbiter.Ignore(); // avoid the collision to continue since this frame return(false); // avoid the collision to continue since this frame } bool collisionFromAbove = GameObjectTools.isHitFromAbove(koopa.transform.position.y, shape2.body, arbiter); if (collisionFromAbove) { // if koopa was jumping then stop forever jumping if (koopa.jump.isJumping()) { koopa.stopJumping(); } // hide the koopa troopa or stop the bouncing of the hidden koopa else if (!koopa._hide.isHidden() || koopa.bounce.isBouncing()) { koopa.hide(); } // kills the koopa else { koopa.die(); } // makes the player jumps a little upwards player.forceJump(); } // koopa starts bouncing else if (koopa._hide.isHidden() && !koopa.bounce.isBouncing()) { koopa.stop(); koopa.bounce.bounce(Mathf.Sign(koopa.transform.position.x - player.transform.position.x)); } // kills Player else { koopa.stop(); arbiter.Ignore(); // avoid the collision to continue since this frame LevelManager.Instance.loseGame(true); // force die animation } // 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); }
public static bool beginCollisionWithPowerUp(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); KoopaTroopa koopa = shape1.getOwnComponent <KoopaTroopa>(); PowerUp powerUp = shape2.getOwnComponent <PowerUp>(); powerUp.Invoke("destroy", 0f); // a replacement for Destroy koopa.stop(); // hide or kill the koopa if (koopa._hide.isHidden()) { koopa.die(); } else { koopa.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(false); }