Skip to content

Commit e24d120

Browse files
Allow the character to flip in both directions
Problem: the character when moving down with angle the sprite was looking up not down so i seperated the code responsible of the flipping
1 parent 6ebd201 commit e24d120

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

getting_started/first_2d_game/03.coding_the_player.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,22 @@ movement. Let's place this code at the end of the ``_process()`` function:
271271

272272
.. tabs::
273273
.. code-tab:: gdscript GDScript
274+
# to allow the
275+
274276

277+
275278
if velocity.x != 0:
276279
$AnimatedSprite2D.animation = "walk"
277-
$AnimatedSprite2D.flip_v = false
278-
# See the note below about the following boolean assignment.
279-
$AnimatedSprite2D.flip_h = velocity.x < 0
280280
elif velocity.y != 0:
281281
$AnimatedSprite2D.animation = "up"
282-
$AnimatedSprite2D.flip_v = velocity.y > 0
283282

283+
# Allow the character to flip in both directions
284+
if velocity.x != 0:
285+
# See the note below about the following boolean assignment.
286+
$AnimatedSprite2D.flip_v = false
287+
$AnimatedSprite2D.flip_h = velocity.x < 0
288+
if velocity.y != 0:
289+
$AnimatedSprite2D.flip_v = velocity.y > 0
284290
.. code-tab:: csharp
285291

286292
if (velocity.X != 0)

0 commit comments

Comments
 (0)