public static bool beginCollisionWithPlayer(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); Goomba goomba = shape1.GetComponent <Goomba>(); Player player = shape2.GetComponent <Player>(); if (goomba.dieAnim.isDying() || player.isDying()) { arbiter.Ignore(); // avoid the collision to continue since this frame return(false); // avoid the collision to continue since this frame } goomba.idle.setIdle(true); // if collides from top then kill the goomba if (GameObjectTools.isHitFromAbove(goomba.transform.position.y, shape2.body, arbiter)) { goomba.die(); // makes the player jumps a little upwards player.forceJump(); } // kills Player else { 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 frame. return(true); }
public static bool beginCollisionWithPowerUp(ChipmunkArbiter arbiter) { ChipmunkShape shape1, shape2; arbiter.GetShapes(out shape1, out shape2); Goomba goomba = shape1.getOwnComponent <Goomba>(); PowerUp powerUp = shape2.getOwnComponent <PowerUp>(); if (goomba.dieAnim.isDying()) { return(false); // avoid the collision to continue since this frame } else { powerUp.Invoke("destroy", 0f); // a replacement for Destroy goomba.die(); } // 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); }