예제 #1
0
    public static bool beginCollisionWithAny(ChipmunkArbiter arbiter)
    {
        ChipmunkShape shape1, shape2;

        // The order of the arguments matches the order in the function name.
        arbiter.GetShapes(out shape1, out shape2);

        // change direction of movement whenever hit something like a wall
        if (GameObjectTools.isWallHit(arbiter))
        {
            Patrol p1 = shape1.GetComponent <Patrol>();
            if (p1 != null && p1.enabled)
            {
                p1.toogleDir();
            }
            Patrol p2 = shape2.GetComponent <Patrol>();
            if (p2 != null && p2.enabled)
            {
                p2.toogleDir();
            }
        }

        // 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);
    }
예제 #2
0
    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);

        // if chasing then avoid wall penetration
        Chase chase = shape1.GetComponent <Chase>();

        if (chase != null && chase.isChasing() && GameObjectTools.isWallHit(arbiter))
        {
            chase.stopChasing();
            chase.enableOperateWhenOutOfSensor();
        }

        // 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);
    }
예제 #3
0
    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);

        Player player = shape1.GetComponent <Player>();

        /*if (player.isDying())
         *      return false; // stop collision with scenery since this frame*/

        player.exitedFromScenery = false;

        // avoid ground penetration (Y axis)
        // NOTE: to solve this Chipmunk has the property collisionBias and/or minPenetrationForPenalty
        Vector2 thePos = player.body.position;
        float   depth  = arbiter.GetDepth(0);

        thePos.y            -= depth;
        player.body.position = thePos;

        // if isn't a grounded surface then stop velocity and avoid getting inside the object
        if (GameObjectTools.isWallHit(arbiter))
        {
            // get sign direction to know what offset apply to body
            player.signCollision = -Mathf.Sign(player.transform.position.x - shape2.transform.position.x);
            // set moving velocity close to 0 so player can't move against the wall but can change direction of movement
            player.walkVelocity = 0.001f;
            // move back to the contact point and a little more
            thePos               = player.body.position;
            thePos.x            += player.signCollision * (depth - 0.01f);
            player.body.position = thePos;
        }

        // 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);
    }