Ejemplo n.º 1
0
 private void Accelerate()
 {
     if (GetInput.Forward())
     {
         float xVelocity = Mathf.Clamp(_velocity.x + _acc * Time.deltaTime, 0, _speed);
         _velocity = _velocity.WithValues(x: xVelocity);
     }
     else if (GetInput.Back())
     {
         float xVelocity = Mathf.Clamp(_velocity.x - _acc * Time.deltaTime, -_speed, 0);
         Debug.Log(xVelocity);
         _velocity = _velocity.WithValues(x: xVelocity);
     }
     else
     {
         _velocity = _velocity.Lerp(Vector3.zero, Time.deltaTime * 3);
     }
 }
Ejemplo n.º 2
0
    void Run()
    {
        if (GetInput.Forward())
        {
            float xVelocity = Mathf.Clamp(velocity.x + runAcceleration * Time.deltaTime, 0, runSpeed);
            velocity = velocity.WithValues(x: xVelocity);
        }
        else if (GetInput.Back())
        {
            float xVelocity = Mathf.Clamp(velocity.x - runAcceleration * Time.deltaTime, -runSpeed, 0);
            velocity = velocity.WithValues(x: xVelocity);
        }
        else
        {
            velocity = velocity.Lerp(Vector3.zero, Time.deltaTime * 3);
        }

        transform.Translate(velocity * Time.deltaTime);
    }