Ejemplo n.º 1
0
    // raycasts towards selected point and returns hit result
    private void CheckCollisionsFor(Vector3 fromPoint, Vector3 toPoint, ref CameraWhisker result)
    {
        RaycastHit outHit;

        result.distance  = (toPoint - fromPoint).magnitude;
        result.hitPoint  = toPoint;
        result.hitNormal = Vector3.zero;

        Vector3 direction = (toPoint - fromPoint).normalized;
        bool    hasHit    =
            Physics.Raycast(
                fromPoint,
                direction,
                out outHit,
                result.distance,
                1   // Default layer
                );

        result.hasHit    = hasHit;
        result.direction = direction;

        if (hasHit)
        {
            result.distance  = outHit.distance;
            result.hitPoint  = outHit.point;
            result.hitNormal = outHit.normal;
        }
    }
Ejemplo n.º 2
0
    // searches through (WHISKERS_COUNT/2) right raycasts and returns the one with the closest hit
    private CameraWhisker FindClosestRightObstacle()
    {
        float minDistance = float.MaxValue;

        // default 45 deg whisker
        CameraWhisker closestObstacleWhisker = null;

        for (int i = (int)(WHISKERS_COUNT * 0.5f); i < WHISKERS_COUNT; i++)
        {
            Vector3 direction = Vector3.Slerp(transform.right, transform.forward, (WHISKERS_COUNT - i) / (WHISKERS_COUNT - WHISKERS_COUNT * 0.5f));
            // rotate the direction towards the character
            direction = Quaternion.Euler(0f, -m_lookOffset, 0f) * direction;

            CheckCollisionsFor(transform.position, transform.position + direction * m_whiskerLength, ref whiskers[i]);
            if (whiskers[i].hasHit)
            {
                if (whiskers[i].distance < minDistance)
                {
                    closestObstacleWhisker = whiskers[i];
                    minDistance            = whiskers[i].distance;
                }
            }
        }

        return(closestObstacleWhisker);
    }
Ejemplo n.º 3
0
    void Awake()
    {
        for(int i = 0; i < WHISKERS_COUNT; i++)
            whiskers[i] = new CameraWhisker();

        tempMaxDistance = maxDistance;
    }
Ejemplo n.º 4
0
    void Awake()
    {
        for (int i = 0; i < WHISKERS_COUNT; i++)
        {
            whiskers[i] = new CameraWhisker();
        }

        tempMaxDistance = maxDistance;
    }
Ejemplo n.º 5
0
    public void CollectCameraWhiskers()
    {
        Vector3 targetFocusDir = (cameraFocusTarget.position - transform.position).normalized;

        CheckCollisionsFor(cameraFocusTarget.position, transform.position, ref lineOfSight);
        CheckCollisionsFor(transform.position, transform.position - targetFocusDir * tempMaxDistance, ref backWhisker);

        left  = FindClosestLeftObstacle();
        right = FindClosestRightObstacle();
    }
Ejemplo n.º 6
0
    public void CollectCameraWhiskers()
    {
        Vector3 targetFocusDir = (cameraFocusTarget.position - transform.position).normalized;

        CheckCollisionsFor(cameraFocusTarget.position, transform.position, ref lineOfSight);
        CheckCollisionsFor(transform.position, transform.position - targetFocusDir * tempMaxDistance, ref backWhisker);

        left = FindClosestLeftObstacle();
        right = FindClosestRightObstacle();
    }
Ejemplo n.º 7
0
    // raycasts towards selected point and returns hit result
    private void CheckCollisionsFor(Vector3 fromPoint, Vector3 toPoint, ref CameraWhisker result)
    {
        RaycastHit outHit;

        result.distance = (toPoint - fromPoint).magnitude;
        result.hitPoint = toPoint;
        result.hitNormal = Vector3.zero;

        Vector3 direction = (toPoint - fromPoint).normalized;
        bool hasHit = 
            Physics.Raycast(
                fromPoint,
                direction,
                out outHit,
                result.distance,
                1   // Default layer
            );
                
        result.hasHit = hasHit;
        result.direction = direction;

        if(hasHit)
        {
            result.distance = outHit.distance;
            result.hitPoint = outHit.point;
            result.hitNormal = outHit.normal;
        }
    }