Esempio n. 1
0
        public void CalculateVelocity(ref Rigidbody2D rigidBody, BaseStats stats, Vector2 direction, Action.MoveAction action)
        {
            rigidBody.velocity += direction * Time.fixedDeltaTime * stats.aceleration;

            if (rigidBody.velocity.magnitude > stats.maxSpeed)
            {
                rigidBody.velocity = rigidBody.velocity.normalized * stats.maxSpeed;
            }

            if (action == Action.MoveAction.BRAKE)
            {
                normalizedBrake = stats.brake;
                normalizedBrake = minBrakeValue + normalizedBrake - (minBrakeValue * normalizedBrake);  // <-- Obligo que sea entre 0.5f y 1f
                normalizedBrake = minBrakeValue - normalizedBrake + 1.0f;                               // <-- Invierto el valoe (cuando 0.5f es 1f, cuando 1f es 0.5f)

                rigidBody.velocity *= normalizedBrake;
                axis *= normalizedBrake;
            }
            else if (action == Action.MoveAction.UP || action == Action.MoveAction.RIGHT || action == Action.MoveAction.DOWN || action == Action.MoveAction.LEFT)
            {
                axis = new Vector3(Input.GetAxis("Horizontal") * 2, Input.GetAxis("Vertical") * 2, 0);
            }
        }
        public void CalculateVelocity(ref Rigidbody2D rigidBody, BaseStats stats, Vector2 direction, Action.MoveAction action)
        {
            rigidBody.velocity += direction * Time.fixedDeltaTime * stats.aceleration;

            if (rigidBody.velocity.magnitude > stats.maxSpeed)
            {
                rigidBody.velocity = rigidBody.velocity.normalized * stats.maxSpeed;
            }

            if (action == Action.MoveAction.BRAKE)
            {
                normalizedBrake = stats.brake;
                normalizedBrake = minBrakeValue + normalizedBrake - (minBrakeValue * normalizedBrake);  // <-- Obligo que sea entre 0.5f y 1f 
                normalizedBrake = minBrakeValue - normalizedBrake + 1.0f;                               // <-- Invierto el valoe (cuando 0.5f es 1f, cuando 1f es 0.5f)

                rigidBody.velocity *= normalizedBrake;
                axis *= normalizedBrake;
            }
            else if (action == Action.MoveAction.UP || action == Action.MoveAction.RIGHT || action == Action.MoveAction.DOWN || action == Action.MoveAction.LEFT)
            {
                axis = new Vector3(Input.GetAxis("Horizontal") * 2, Input.GetAxis("Vertical") * 2, 0);
            }

        }