Esempio n. 1
0
    void Update()
    {
        float deltaTime = (unscaledTime ? Time.unscaledDeltaTime : Time.deltaTime) * timescale;

        if (hitDelta.sqrMagnitude > 0)
        {
            hitDelta = Vector2.Lerp(hitDelta, Vector2.zero, FixedLerp.Fix(hitQuitSpeed, FPSCounter.GetFPS() / timescale));
        }

        float targetStrength = GetTargetStrength();
        float targetSpeed    = targetStrength > 0 ? speed : 0;


        if (quitDuration <= 0)
        {
            currentSpeed    = targetSpeed;
            currentStrength = targetStrength;
        }
        else
        {
            float speedMoveSpeed = (speed / quitDuration) * deltaTime;

            float strengthMoveSpeed = float.PositiveInfinity;
            float deltaSpeed        = Math.Abs(targetSpeed - currentSpeed);
            if (deltaSpeed > 0)
            {
                strengthMoveSpeed = (Mathf.Abs(currentStrength - targetStrength) /      //Quantite restante
                                     (deltaSpeed / speedMoveSpeed));                    //Nombre de frame restante
            }
            currentStrength = Mathf.MoveTowards(currentStrength, targetStrength, strengthMoveSpeed);
            currentSpeed    = Mathf.MoveTowards(currentSpeed, targetSpeed, speedMoveSpeed);
        }

        if (currentStrength > 0)
        {
            float height = (Mathf.PerlinNoise(time, 0) * 2 - 1) * currentStrength;
            float width  = (Mathf.PerlinNoise(0, time) * 2 - 1) * currentStrength;

            shakeDelta = new Vector2(height, width);
        }
        else
        {
            shakeDelta = Vector2.zero;
        }

        if (smoothFactor > 1)
        {
            realSmoothedDelta = Vector2.Lerp(realSmoothedDelta, hitDelta + shakeDelta, FixedLerp.Fix(1 / smoothFactor, FPSCounter.GetFPS() / timescale));
        }
        else
        {
            realSmoothedDelta = hitDelta + shakeDelta;
        }

        time += deltaTime * currentSpeed;
        UpdateTimedShakers(deltaTime);
    }
Esempio n. 2
0
    void FixedUpdate()
    {
        if (movementEnable == false)
        {
            rb.velocity = Vector2.zero;
            return;
        }

        Vector2 distance  = currentTarget - (Vector2)transform.position;
        Vector2 direction = distance.normalized;
        Vector2 Speed     = Vector2.Lerp(
            rb.velocity,
            direction * maximumSpeed,
            FixedLerp.Fix(0.1f * accelerationRate));

        rb.velocity = Speed;
    }
Esempio n. 3
0
    void Update()
    {
        float speed = 0;

        if (useRigidbody)
        {
            speed = rb.velocity.magnitude;
            if (speed > sensitivity)
            {
                animatorController.SetBool(runHash, true);
                targetAngle = rb.velocity.ToAngle();
            }
            else
            {
                animatorController.SetBool(runHash, false);
            }
        }
        else
        {
            speed = playerMovement.LastPlayerInput.magnitude;
            animatorController.SetBool(runHash, playerMovement.IsMoving);
            if (playerMovement.IsMoving && speed > sensitivity)
            {
                targetAngle = playerMovement.LastPlayerInput.ToAngle();
            }
        }

        if (setSpeed)
        {
            animatorController.SetFloat(speedHash, speed * speedScale);
        }



        currentAngle     = Mathf.LerpAngle(currentAngle, targetAngle, FixedLerp.Fix(lerpSpeed));
        rotator.rotation = Quaternion.Euler(Vector3.forward * currentAngle);
    }
Esempio n. 4
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F) && isMaster)
        {
            follow = true;
        }

        if (follow)
        {
            Transform camT = Camera.main.transform;
            Vector3   pos  = transform.position;
            camT.position = camT.position.Lerpped(new Vector3(pos.x, pos.y, camT.position.z) + offset, FixedLerp.Fix(0.1f));
        }

        offset = offset.MovedTowards(Vector3.zero, Time.deltaTime * 10);

        canContaminate = true;
    }