Example #1
0
    private IEnumerator SnapView(Vector3 old, Vector3 current, float duration, bool playerHasMoved)
    {
        snapViewRunning = true;
        float elapsedTime = 0;
        float ratio       = 0;

        while (ratio < 1f)
        {
            ratio = elapsedTime / duration;
            Vector3 view = Vector3.Lerp(old, current, TweeningFunctions.EaseOutCubic(ratio));
            transform.LookAt(view);
            elapsedTime += Time.deltaTime;
            SetBeamLength(hitPoint);

            if (playerHasMoved)
            {
                //doing lerp for focal scale
                float start = beam.transform.localScale.x;
                float width = Mathf.Lerp(start, unfocusedScale, ratio);
                beam.SetWidth(width);
            }

            yield return(null);
        }

        lastTarget      = current;
        snapViewRunning = false;
    }
Example #2
0
    private IEnumerator SnapView(Vector3 current, float duration, bool toPlayer)
    {
        snapViewRunning = true;
        float   elapsedTime = 0;
        float   ratio       = 0;
        Vector3 start       = transform.position + transform.forward;//beamEnd.position;//= new Vector3(transform.position.x, transform.position.y, transform.position.z + beam.transform.localScale.z);
        Vector3 end         = current;
        float   beamStart   = beam.transform.localScale.z;


        while (ratio < 1f)
        {
            ratio = elapsedTime / duration;
            Vector3 view = Vector3.Lerp(start, end, TweeningFunctions.EaseOutCubic(ratio));
            transform.LookAt(view);
            elapsedTime += Time.deltaTime;
            SetBeamLength(current);

            if (toPlayer)
            {
                float length = Mathf.Lerp(beamStart, 0f, TweeningFunctions.EaseOutCubic(ratio));
                beam.SetLength(length);
            }

            yield return(null);
        }

        snapViewRunning = false;

        if (toPlayer && state != BotState.Speaking)
        {
            state = BotState.Following;
        }
    }
Example #3
0
    private IEnumerator ResetBeamLength(float duration)
    //for after it's looked at the player
    {
        float elapsedTime = 0;
        float ratio       = elapsedTime / duration;

        while (ratio < 1f)
        {
            ratio        = elapsedTime / duration;
            elapsedTime += Time.deltaTime;

            //doing lerp for focal scale
            float start  = beam.transform.localScale.z;
            float length = Mathf.Lerp(start, 0f, TweeningFunctions.EaseOutCubic(ratio));
            beam.SetLength(length);

            yield return(null);
        }
    }
Example #4
0
    void FixedUpdate()
    {
        if (elapsedTime < mySpeed)
        {
            var ratio = elapsedTime / mySpeed;

            float currentScale = Mathf.Lerp(startScale, endScale, TweeningFunctions.EaseOutCubic(ratio));

            transform.localScale = new Vector3(currentScale, currentScale, currentScale);

            material.SetFloat("_TransitionState", TweeningFunctions.EaseOutCubic(ratio));

            elapsedTime += Time.fixedDeltaTime;
        }
        else
        {
            UnityEngine.Object.Destroy(this.gameObject);
        }
    }
Example #5
0
    private IEnumerator Focus(float duration)
    //for after it's looked at the player
    {
        //Debug.Log("widening focus");
        widenFocusRunning = true;
        float elapsedTime = 0;
        float ratio       = elapsedTime / duration;

        while (ratio < 1f)
        {
            ratio        = elapsedTime / duration;
            elapsedTime += Time.deltaTime;

            //doing lerp for focal scale
            float start = beam.transform.localScale.x;
            float width = Mathf.Lerp(start, focusedScale, TweeningFunctions.EaseOutCubic(ratio));
            beam.SetWidth(width);

            yield return(null);
        }

        widenFocusRunning = false;
    }