// Move/rotate after main tick
    private void FixedUpdate()
    {
        moveToTarget();
        if (_camMode == CameraModes.SNAP_ORBIT)
        {
            snapOrbit();
        }
        //orbitTarget();
        lookAtTarget();

        _collisionHandler.UpdateCameraClipPoints(transform.position, transform.rotation, ref _collisionHandler.AdjustedCameraClipPoints);
        _collisionHandler.UpdateCameraClipPoints(_destination, transform.rotation, ref _collisionHandler.DesiredCameraClipPoints);

        for (var i = 0; i < 5; i++)
        {
            if (_debug.DrawAdjustedLines)
            {
                Debug.DrawLine(_targetPos, _collisionHandler.AdjustedCameraClipPoints[i], Color.green);
            }
            if (_debug.DrawDesiredLines)
            {
                Debug.DrawLine(_targetPos, _collisionHandler.DesiredCameraClipPoints[i], Color.white);
            }
        }
        _collisionHandler.CheckColliding(_targetPos);
        _position.AdjustmentDistance = _collisionHandler.GetAdjustedDistanceWithRay(_targetPos);
    }
Ejemplo n.º 2
0
    private void FixedUpdate()
    {
        LookAtTarget();
        MoveToTarget();

        collisionHandler.UpdateCamClipPoints(transform.position, transform.rotation, ref collisionHandler.adjCameraClipPoints);
        collisionHandler.UpdateCamClipPoints(destination, transform.rotation, ref collisionHandler.desCameraClipPoints);

        collisionHandler.CheckColliding(targetPos);
        positionSettings.adjustmentDist = collisionHandler.CamDistToTarget(targetPos);
    }
Ejemplo n.º 3
0
    private Vector3 CalculateCollisionAdjustments()
    {
        Vector3 adjustment = Vector3.zero;

        CollisionHandler.UpdateCameraClipPoints(transform.position, transform.rotation, ref CollisionHandler.AdjustedCameraClipPoints);
        CollisionHandler.UpdateCameraClipPoints(m_finalPosition, transform.rotation, ref CollisionHandler.DesiredCameraClipPoints);

        CollisionHandler.CheckColliding(FollowObject.transform.position);

        if (CollisionHandler.Colliding)
        {
            float adjustmentDistance = CollisionHandler.GetAdjustedDistanceWithRayFrom(FollowObject.transform.position);
            adjustment = Quaternion.Euler(transform.eulerAngles.x, transform.eulerAngles.y + FollowObject.eulerAngles.y, 0) *
                         -Vector3.forward * (adjustmentDistance - Vector3.Distance(FollowObject.transform.position, m_finalPosition));
        }

        adjustment = Vector3.SmoothDamp(m_lastAdjustment, adjustment, ref m_cameraLerpVelocity, AdjustSmoothing);

        return(adjustment);
    }
Ejemplo n.º 4
0
    void CamControl()
    {
        mouseXValue += Input.GetAxis(mouseXId) * rotationSpeed;
        mouseYValue -= Input.GetAxis(mouseYId) * rotationSpeed;

        mouseYValue = Mathf.Clamp(mouseYValue, -35, 60);

        //allow player to control camera seperate from player movement
        if (Input.GetKey(cameraFreeMovementKey))
        {
            target.rotation = Quaternion.Euler(mouseYValue, mouseXValue, 0);
        }
        //turn player along with camera's rotation
        else
        {
            target.rotation = Quaternion.Euler(mouseYValue, mouseXValue, 0);
            player.rotation = Quaternion.Euler(0, mouseXValue, 0);
        }

        //zoom controls and functionality
        if (Input.GetAxis(mouseScrollId) != 0)
        {
            //prevent getting stuck in a loop when zooming back out from 0 distance;
            if (distanceFromTarget == 0)
            {
                distanceFromTarget++;
            }
            distanceFromTarget += -Input.GetAxis(mouseScrollId) * zoomSpeed;
            distanceFromTarget  = Mathf.Clamp(distanceFromTarget, minZoomDistance, maxZoomDistance);
        }
        //enter first person view when zooming in at a close distance
        else if (distanceFromTarget < 2)
        {
            distanceFromTarget = 0;
        }

        //using raycasts here
        collision.CheckColliding(target.position);
        adjustmentDistance = collision.GetAdjustedDistanceWithRayFrom(target.position);

        if (collision.colliding)
        {
            //enter first person view when colliding at a close distance behind player
            if (adjustmentDistance < 1)
            {
                adjustmentDistance = 0;
            }
            adjustedDestination = target.position - transform.forward * adjustmentDistance;

            if (smoothFollow)
            {
                //smoothening camera's position change transition
                transform.position = Vector3.SmoothDamp(transform.position, adjustedDestination, ref camVel, smooth);
            }
            else
            {
                transform.position = adjustedDestination;
            }
        }
        else
        {
            destination = target.position - transform.forward * distanceFromTarget;
            if (smoothFollow)
            {
                transform.position = Vector3.SmoothDamp(transform.position, destination, ref camVel, smooth);
            }
            else
            {
                transform.position = destination;
            }
        }
    }