コード例 #1
0
    IEnumerator SmoothMove()
    {
        isMoving = true;
        t        = 0.0f;
        while (t <= 1.0)
        {
            t += Time.deltaTime / seconds;
            float v = t;
            if (easeInOut)
            {
                v = EasingFunction.EaseInOutQuad(0.0f, 1.0f, t);
            }
            Vector3 newPosition = Vector3.Lerp(startPos, endpos, v);

            Vector2 pixelPerfectMoveAmount = Utils.MakePixelPerfect(newPosition);
            transform.position = pixelPerfectMoveAmount;

            yield return(new WaitForEndOfFrame());
        }
        if (biDirectional)
        {
            endpos   = startPos;
            startPos = transform.position;
        }

        isMoving = false;
    }
コード例 #2
0
ファイル: BookScript.cs プロジェクト: thquinn/Bookbinding
    void Update()
    {
        if (isDead)
        {
            deadSpeed += deadAccel;
            transform.Translate(0, 0, -deadSpeed);
            if (transform.position.z < -100)
            {
                Destroy(gameObject);
            }
            return;
        }

        // Tilt.
        if (tilt >= GameScript.MAX_TILT)   // Drop the book; the game is over.
        {
            tilt = Mathf.Min(90, tilt + 3);
        }
        float actualTilt = tiltParent.transform.localRotation.eulerAngles.z;

        if (actualTilt != tilt)
        {
            float zRot = Mathf.Abs(tilt - actualTilt) < .5f ? tilt : actualTilt + (tilt - actualTilt) * TILT_TWEEN_SPEED;
            float zRadians = zRot * Mathf.Deg2Rad;
            float zSin = Mathf.Sin(zRadians);
            float z2Sin = Mathf.Sin(zRadians * 2);
            float width = model.transform.localScale.x, height = model.transform.localScale.y * 8;
            float xOff = (height / 2 - width / 2) * zSin + (height / 20) * z2Sin;
            float yOff = (width / 2 - height / 2) * zSin + (height / 5) * z2Sin;
            tiltParent.transform.localPosition = new Vector3(xOff, yOff, 0);
            tiltParent.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, zRot));
        }
        // Tween.
        if (xTweenTime < 1)
        {
            xTweenTime = Mathf.Min(1, xTweenTime + xTweenSpeed);
            if (!ready && xTweenTime >= .9f)
            {
                audioSource.PlayOneShot(thumpClips[Random.Range(0, thumpClips.Length)]);
                ready = true;
            }
            float x = EasingFunction.EaseInOutQuad(xTweenStart, 0, xTweenTime);
            float z = EasingFunction.EaseInQuad(0, 1, xTweenTime);
            if (z > .5)
            {
                z = 1 - z;
            }
            z *= 2;
            float y    = zTweenFront ? z / 2 : 0;
            float xRot = zTweenFront ? z * -3 : 0;
            z *= zTweenFront ? -5f : 2.5f;
            tweenParent.transform.localPosition = new Vector3(x, y, z);
            tweenParent.transform.localRotation = Quaternion.Euler(new Vector3(xRot, 0, 0));
        }
    }
コード例 #3
0
    public IEnumerator EnergyChange(float targetValue, float time)
    {
        float startValue = energyFillSprite.fillAmount;

        for (float i = 0f; i <= time;)
        {
            i += Time.deltaTime;
            float currentTime = Mathf.Min(i / time, 1f);
            energyFillSprite.fillAmount = EasingFunction.EaseInOutQuad(startValue, targetValue, currentTime);
            yield return(null);
        }
    }
コード例 #4
0
    //Only used for camera movement for smoothing purposes
    public void LateUpdate()
    {
        float inputVert = _lookInput.x;
        //Up/Down aiming
        Quaternion headRot      = Head.transform.localRotation;
        Vector3    headRotEuler = headRot.eulerAngles;

        headRotEuler.x = ClampAngle(headRotEuler.x + inputVert * Mathf.Lerp(LookMinSensitivity, LookMaxSensitivity, Mathf.Abs(inputVert)),
                                    MinVerticalAngle,
                                    MaxVerticalAngle
                                    );
        Head.transform.localRotation = Quaternion.Lerp(headRot, Quaternion.Euler(headRotEuler), Time.deltaTime * LookSharpness);
        float percent = (_currentMoveSpeed - GroundMoveSpeed) / (GroundRunSpeed - GroundMoveSpeed);

        PlayerCamera.fieldOfView = BaseFOV + Mathf.Lerp(MinFOVAdd, MaxFOVAdd, EasingFunction.EaseInOutQuad(0f, 1f, percent));
    }
コード例 #5
0
    IEnumerator MoveCamera()
    {
        float t = 0.0f;

        while (t <= 1.0)
        {
            t += Time.deltaTime / cameraMoveSeconds;
            float v = t;
            v = EasingFunction.EaseInOutQuad(0.0f, 1.0f, t);
            Vector3 newPosition = Vector3.Lerp(startPos, endPos, v);

            Vector2 pixelPerfectMoveAmount = Utils.MakePixelPerfect(newPosition);
            Vector3 newPos = new Vector3(pixelPerfectMoveAmount.x, pixelPerfectMoveAmount.y, Camera.main.transform.position.z);
            Camera.main.transform.position = newPos;

            yield return(new WaitForEndOfFrame());
        }
    }
コード例 #6
0
    void Update()
    {
        if (GameEngine.Current.IsPlaying())
        {
            PercentTraveled += Time.deltaTime * Speed;
            PercentTraveled  = Mathf.Clamp(PercentTraveled, 0, 1);

            var pos = transform.position;
            pos = Vector3.Lerp(Source, Destination, EasingFunction.EaseInOutQuad(0, 1, PercentTraveled));
            transform.position = pos;

            if (PercentTraveled >= 1)
            {
                PercentTraveled = -100;
                DestinationGriddle.AddResource(Resource, Quantity);
                this.Despawn();
            }
        }
    }
コード例 #7
0
    void UpdateTransition()
    {
        UpdateTrains(lastLevel, false);
        float previousT = transitionT;

        transitionT = Mathf.Min(1, transitionT + TRANSITION_SPEED);
        if (previousT < .5f && transitionT >= .5f)
        {
            t     = 0;
            speed = 0;
            UpdateTrains(level);
            UpdateAudio();
        }
        float   easedT  = EasingFunction.EaseInOutQuad(0, 1, transitionT);
        Vector3 lastPos = root.transform.localPosition;

        root.transform.localPosition = Vector3.Lerp(transitionFrom, transitionTo, easedT);
        Vector3 delta = root.transform.localPosition - lastPos;

        lastRoot.transform.localPosition     += delta;
        gridObject.transform.localPosition   += delta;
        gridObject.transform.localPosition    = new Vector3(gridObject.transform.localPosition.x % 1, gridObject.transform.localPosition.y, gridObject.transform.localPosition.z % 1);
        smokesObject.transform.localPosition += delta;
        float lastZoom = lastLevel.OrthographicSize();
        float nextZoom = level.OrthographicSize();

        cam.orthographicSize = Mathf.Lerp(lastZoom, nextZoom, easedT);
        if (transitionT >= 1)
        {
            foreach (Train train in lastLevel.trains)
            {
                trainObjects.Remove(train);
            }
            foreach (Train train in lastLevel.deadTrains)
            {
                trainObjects.Remove(train);
            }
            lastLevel = null;
            Destroy(lastRoot);
        }
    }
コード例 #8
0
    public IEnumerator MoveCameraBack(float cameraMoveSeconds, Vector2 startPos)
    {
        float   t      = 0.0f;
        Vector2 endPos = target.transform.position + Vector3.right * postInitOffsets.x + Vector3.up * postInitOffsets.y;

        while (t <= 1.0)
        {
            t += Time.deltaTime / cameraMoveSeconds;
            float v = t;
            v = EasingFunction.EaseInOutQuad(0.0f, 1.0f, t);
            Vector3 newPosition = Vector3.Lerp(startPos, endPos, v);

            Vector2 pixelPerfectMoveAmount = Utils.MakePixelPerfect(newPosition);
            Vector3 newPos = new Vector3(pixelPerfectMoveAmount.x, pixelPerfectMoveAmount.y, Camera.main.transform.position.z);
            Camera.main.transform.position = newPos;

            yield return(new WaitForEndOfFrame());
        }
        enabled = true;
        Init();
    }
コード例 #9
0
    // Update is called once per frame
    void Update()
    {
        float now = Time.time;

        if (now > endTime)
        {
            SwapAnimation();
        }

        float newValue = 0f;
        float howFar   = 1 - ((endTime - now) / animationDuration);

        if (isFloatingUp)
        {
            newValue = EasingFunction.EaseInOutQuad(baseY, maxY, howFar);
        }
        else
        {
            newValue = EasingFunction.EaseInOutQuad(maxY, baseY, howFar);
        }
        this.transform.localPosition = new Vector3(this.transform.localPosition.x, newValue, 0);
    }
コード例 #10
0
    // Update is called once per frame
    void Update()
    {
        float now = Time.time;

        if (now > endTime)
        {
            SwapAnimation();
        }

        float newValue = 0f;
        float howFar   = 1 - ((endTime - now) / animationDuration);

        if (isTiltingForward)
        {
            newValue = EasingFunction.EaseInOutQuad(minZ, maxZ, howFar);
        }
        else
        {
            newValue = EasingFunction.EaseInOutQuad(maxZ, minZ, howFar);
        }
        //Debug.Log ("Stoffer " + transform.localRotation.ToString ());
        this.transform.localRotation = new Quaternion(0f, 0f, newValue, 1.0f);
    }
コード例 #11
0
    IEnumerator MoveCamera()
    {
        float t = 0.0f;

        while (t <= 1.0)
        {
            t += Time.deltaTime / cameraMoveSeconds;
            float v = t;
            v = EasingFunction.EaseInOutQuad(0.0f, 1.0f, t);
            Vector3 newPosition = Vector3.Lerp(startPos, endPos, v);

            Vector2 pixelPerfectMoveAmount = Utils.MakePixelPerfect(newPosition);
            Vector3 newPos = new Vector3(pixelPerfectMoveAmount.x, pixelPerfectMoveAmount.y, Camera.main.transform.position.z);
            Camera.main.transform.position = newPos;

            yield return(new WaitForEndOfFrame());
        }
        if (!inDialogue)
        {
            CameraFollow.GetInstance().enabled             = true;
            InputController.GetInstance().moveInputEnabled = true;
        }
    }
コード例 #12
0
    private void SmoothMoveUpDown()
    {
        if (t <= 1.0)
        {
            t += Time.deltaTime / secondsBounce;
            float newTime = t;
            if (newTime > 1)
            {
                newTime = 1;
            }
            float easeFactor = EasingFunction.EaseInOutQuad(0.0F, 1.0F, newTime);

            Vector2 newPosition            = Vector2.Lerp(startPos, endPos, easeFactor);
            Vector3 pixelPerfectMoveAmount = Utils.MakePixelPerfect(newPosition);
            transform.Translate(pixelPerfectMoveAmount - transform.position);
        }
        else
        {
            t = 0;
            Vector3 dummy = startPos;
            startPos = endPos;
            endPos   = dummy;
        }
    }