Ejemplo n.º 1
0
    private void LateUpdate()
    {
        currentHorizAngle = CalculateHorizontalAngle();

        float horizAngRad = currentHorizAngle * Mathfs.Deg2Rad;
        float vertAngRad  = VerticalAngle * Mathfs.Deg2Rad;

        Vector3 desiredRelativePosition = new Vector3(Mathfs.Cos(horizAngRad),
                                                      Mathfs.Sin(vertAngRad),
                                                      Mathfs.Sin(horizAngRad)) * Flatness;

        var followTargetPosition     = FollowTarget.position;
        var focalPointToFollowTarget = followTargetPosition - currentFocalPoint;
        var focalPointDelta          = Vector3.Dot(focalPointToFollowTarget, focalPointToFollowTarget);

        float smoothingFactor = Mathfs.Clamp01(focalPointDelta) * trackingSpeed * Time.deltaTime;

        currentFocalPoint         = Vector3.MoveTowards(currentFocalPoint, followTargetPosition, smoothingFactor);
        currentRotatedRelativePos = Vector3.Slerp(currentRotatedRelativePos, desiredRelativePosition, RotateSpeed * Time.deltaTime);

        transform.position = currentFocalPoint + currentRotatedRelativePos;
        transform.rotation = Quaternion.LookRotation(currentFocalPoint - transform.position, Vector3.up);

        // tie FoV to distance
        cam.fieldOfView = Mathf.Atan(Zoomness / Flatness) * Mathf.Rad2Deg * 2.0f;
    }
Ejemplo n.º 2
0
        // Methods
        private Vector3 PickNewPatrolPoint()
        {
            NavMeshHit         meshHit;
            NavMeshQueryFilter queryFilter = new NavMeshQueryFilter();

            queryFilter.areaMask = ~0;
            Vector3 point;

            do
            {
                float   angRad = Random.Range(0.0f, Mathfs.TAU);
                Vector3 dir    = new Vector3(Mathfs.Cos(angRad), 0.0f, Mathfs.Sin(angRad)).normalized;
                point = dir * Random.Range(0.0f, radius);
            } while (!NavMesh.SamplePosition(initPosition.GetInitialPosition() + point, out meshHit, radius, queryFilter) &&
                     Vector3.Distance(meshHit.position, enemyBehaviour.transform.position) < agent.stoppingDistance);

            return(meshHit.position);
        }
    private static IEnumerator _WipeToBlackFromCenter(float startingRadius, float time)
    {
        float elapsed = 0.0f;

        while (elapsed < time)
        {
            float progress = elapsed / time;
            float t        = 1 - Mathfs.Cos(progress * Mathfs.TAU / 4.0f);

            float radius = Mathfs.Lerp(startingRadius, 0, t);
            Instance._tempMaterial.SetFloat(Radius, radius);

            yield return(WaitForEndOfFrame);

            elapsed += Time.deltaTime;
        }

        Instance._tempMaterial.SetFloat(Alpha, 1.0f);
        Instance._tempMaterial.SetFloat(Radius, -1.0f);
    }
    private static IEnumerator _WipeToBlack(Vector3 position, float startingRadius, float time)
    {
        float elapsed = 0.0f;

        while (elapsed < time)
        {
            Vector2 coords = _cam.WorldToScreenPoint(position);
            Instance._tempMaterial.SetFloat(CenterX, coords.x);
            Instance._tempMaterial.SetFloat(CenterY, coords.y);

            float progress = elapsed / time;
            float t        = 1 - Mathfs.Cos(progress * Mathfs.TAU / 4.0f);

            float radius = Mathfs.Lerp(startingRadius, 0, t);
            Instance._tempMaterial.SetFloat(Radius, radius);

            yield return(WaitForEndOfFrame);

            elapsed += Time.deltaTime;
        }

        Instance._tempMaterial.SetFloat(Alpha, 1.0f);
        Instance._tempMaterial.SetFloat(Radius, -1.0f);
    }