Ejemplo n.º 1
0
    private Vector2 ApplyAcceleration()
    {
        acceleration.timer += Time.deltaTime;
        if (acceleration.timer < acceleration.duration)
        {
            float ratio = acceleration.GetRatio();
            float speed = Mathf.Lerp(0f, speedMax, ratio);

            return(moveDirection * speed);
        }
        else
        {
            return(moveDirection * speedMax);
        }
    }
Ejemplo n.º 2
0
    private Vector2 ApplyFrictions(Vector2 velocity)
    {
        frictions.timer += Time.deltaTime;
        if (frictions.timer < frictions.duration)
        {
            float ratio = frictions.GetRatio();
            float speed = Mathf.Lerp(speedMax, 0f, ratio);
            velocity = velocity.normalized * speed;
        }
        else
        {
            velocity          = Vector2.zero;
            prevMoveDirection = Vector2.zero;
        }

        return(velocity);
    }
Ejemplo n.º 3
0
    private Vector2 ApplyTurn(Vector2 velocity)
    {
        if (isTurning)
        {
            turn.timer += Time.deltaTime;
            if (turn.timer < turn.duration)
            {
                float ratio = turn.GetRatio();
                velocity = Vector2.Lerp(turnVelocityStart, velocity, ratio);
            }
            else
            {
                isTurning = false;
            }
        }

        return(velocity);
    }
Ejemplo n.º 4
0
    private Vector2 ApplyTurnAround(Vector2 velocity)
    {
        turnAround.timer += Time.deltaTime;
        if (turnAround.timer < turnAround.duration)
        {
            float ratio = turnAround.GetRatio();
            float speed = Mathf.Lerp(turnAroundVelocityStart, 0f, ratio);
            velocity = velocity.normalized * speed;
        }
        else
        {
            velocity           = Vector2.zero;
            acceleration.timer = 0f;
            isTurningAround    = false;
        }

        return(velocity);
    }
Ejemplo n.º 5
0
 public void UpdateDash()
 {
     if (dash.timer < dash.duration)
     {
         dash.timer += Time.fixedDeltaTime;
         float ratio = dash.GetRatio();
         float speed = Mathf.Lerp(dashVelocityStart, dashSpeed, ratio);
         velocity = dashDirection * speed;
         if (rigidBody != null)
         {
             rigidBody.velocity = velocity;
         }
     }
     else
     {
         isDashing = false;
         velocity  = dashDirection * speedMax;
         if (rigidBody != null)
         {
             rigidBody.velocity = velocity.ConvertTo3D();
         }
         StartCoroutine(DashCooldown(dashCooldown));
     }
 }