Skip to content

Commit

Permalink
Clarify deadzone difference for Input.get_vector() in Controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou committed Feb 14, 2021
1 parent db60a7e commit b31b0b6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tutorials/inputs/controllers_gamepads_joysticks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,24 @@ In Godot 4.0, there are 3 ways to get input in an analog-aware way:
.. code-tab:: gdscript GDScript

# `velocity` will be a Vector2 between `Vector2(-1.0, -1.0)` and `Vector2(1.0, 1.0)`.
# This handles deadzone in a correct way. The resulting deadzone will have a circular shape
# as it should.
var velocity = Input.get_vector("move_left", "move_right", "move_forward", "move_back")

# The line above is a shorter form of:
# The line below handles deadzone in an incorrect way. The resulting deadzone
# will have a square shape when it should have a circular shape.
var velocity = Vector2(Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")).clamped(1)

.. code-tab:: csharp

// `velocity` will be a Vector2 between `Vector2(-1.0, -1.0)` and `Vector2(1.0, 1.0)`.
// This handles deadzone in a correct way. The resulting deadzone will have a circular shape
// as it should.
Vector2 velocity = Input.GetVector("move_left", "move_right", "move_forward", "move_back");

// The line above is a shorter form of:
// The linew below handles deadzone in an incorrect way. The resulting deadzone
// will have a square shape when it should have a circular shape.
Vector2 velocity = new Vector2(Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left"),
Input.GetActionStrength("move_back") - Input.GetActionStrength("move_forward")).Clamped(1);

Expand Down

0 comments on commit b31b0b6

Please sign in to comment.