Merge branch 'master' into 3.2
@@ -13,6 +13,8 @@ the movement in most 2D games is based on a small number of designs.
|
||||
We'll use :ref:`KinematicBody2D <class_KinematicBody2D>` for these examples,
|
||||
but the principles will apply to other node types (Area2D, RigidBody2D) as well.
|
||||
|
||||
.. _doc_2d_movement_setup:
|
||||
|
||||
Setup
|
||||
-----
|
||||
|
||||
@@ -98,7 +100,7 @@ Add a script to the kinematic body and add the following code:
|
||||
}
|
||||
}
|
||||
|
||||
In the ``get_input()`` function we check for the four key events and sum them
|
||||
In the ``get_input()`` function, we check for the four key events and sum them
|
||||
up to get the velocity vector. This has the benefit of making two opposite keys
|
||||
cancel each other out, but will also result in diagonal movement being faster
|
||||
due to the two directions being added together.
|
||||
@@ -109,6 +111,12 @@ its *length* to ``1``, and multiply by the desired speed.
|
||||
.. tip:: If you've never used vector math before, or need a refresher,
|
||||
you can see an explanation of vector usage in Godot at :ref:`doc_vector_math`.
|
||||
|
||||
.. note::
|
||||
|
||||
If the code above does nothing when you press the keys, double-check that
|
||||
you've set up input actions correctly as described in the
|
||||
:ref:`doc_2d_movement_setup` part of this tutorial.
|
||||
|
||||
Rotation + movement
|
||||
-------------------
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 372 KiB |
|
Before Width: | Height: | Size: 438 KiB |
|
Before Width: | Height: | Size: 1.0 MiB |
|
Before Width: | Height: | Size: 233 KiB |
|
Before Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 5.6 KiB |
|
Before Width: | Height: | Size: 30 KiB |
|
Before Width: | Height: | Size: 65 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.7 KiB |
|
Before Width: | Height: | Size: 8.1 KiB |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 5.2 KiB |
|
Before Width: | Height: | Size: 4.8 KiB |