void CheckForCollisions()
    {
        Bounds bounds;

        for (int i = 0; i < smoothedPointIndex; i++)
        {
            if (colliderManager.CheckForIntersections(smoothedPoints[i], out bounds))
            {
                pathCollides = true;
                if (i > 0)
                {
                    Vector3 pointOnBounds = bounds.ClosestPoint(smoothedPoints[i - 1]);
                    Vector3 direction     = smoothedPoints[i - 1] - pointOnBounds;
                    colliderStopPosition   = pointOnBounds + (direction.normalized * player.PlayerBounds.extents.x);
                    colliderStopPosition.y = smoothedPoints[i - 1].y;
                }
                else
                {
                    colliderStopPosition = smoothedPoints[0];
                }

                smoothedPointIndex = i;

                return;
            }
        }
    }
Beispiel #2
0
    private void Update()
    {
        PlayerBounds = characterController.bounds;
        Bounds collisionBounds;

        //stay on the ground unless youre hanging
        if (stateManager.CURRENT_STATE != StateManager.PLAYER_STATE.HANG)
        {
            transform.position = new Vector3(transform.position.x, 0.2f, transform.position.z);
        }

        if (colliderManager.CheckForIntersections(transform.position, out collisionBounds))
        {
            Vector3 target = collisionBounds.ClosestPoint(transform.position);
            target.y = transform.position.y;

            //incase we get 'trapped' inside the collider, just
            //move towards the origin.
            while (collisionBounds.Contains(target))
            {
                target = Vector3.MoveTowards(target, Vector3.zero, 0.25f);
            }

            Vector3 move = target - transform.position;
            move.y = 0;

            characterController.Move(move);
        }
    }