From e24d12062818dbb7c9502f38f5c16cee4414a67e Mon Sep 17 00:00:00 2001 From: Anas Mustafa <104536579+anasmustafa123@users.noreply.github.com> Date: Mon, 6 Oct 2025 03:27:22 +0300 Subject: [PATCH 1/4] 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 --- .../first_2d_game/03.coding_the_player.rst | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/getting_started/first_2d_game/03.coding_the_player.rst b/getting_started/first_2d_game/03.coding_the_player.rst index 2548f77ffad..0be2f6d5ae8 100644 --- a/getting_started/first_2d_game/03.coding_the_player.rst +++ b/getting_started/first_2d_game/03.coding_the_player.rst @@ -271,16 +271,22 @@ movement. Let's place this code at the end of the ``_process()`` function: .. tabs:: .. code-tab:: gdscript GDScript + # to allow the + + if velocity.x != 0: $AnimatedSprite2D.animation = "walk" - $AnimatedSprite2D.flip_v = false - # See the note below about the following boolean assignment. - $AnimatedSprite2D.flip_h = velocity.x < 0 elif velocity.y != 0: $AnimatedSprite2D.animation = "up" - $AnimatedSprite2D.flip_v = velocity.y > 0 + # Allow the character to flip in both directions + if velocity.x != 0: + # See the note below about the following boolean assignment. + $AnimatedSprite2D.flip_v = false + $AnimatedSprite2D.flip_h = velocity.x < 0 + if velocity.y != 0: + $AnimatedSprite2D.flip_v = velocity.y > 0 .. code-tab:: csharp if (velocity.X != 0) From 39db686ca2a0b976261064c89de6fd6ba9bbace3 Mon Sep 17 00:00:00 2001 From: Anas Mustafa <104536579+anasmustafa123@users.noreply.github.com> Date: Mon, 6 Oct 2025 13:09:13 +0300 Subject: [PATCH 2/4] Clean up comments in player movement code Removed unnecessary comments in GDScript code. --- getting_started/first_2d_game/03.coding_the_player.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/getting_started/first_2d_game/03.coding_the_player.rst b/getting_started/first_2d_game/03.coding_the_player.rst index 0be2f6d5ae8..591d20a28d2 100644 --- a/getting_started/first_2d_game/03.coding_the_player.rst +++ b/getting_started/first_2d_game/03.coding_the_player.rst @@ -271,10 +271,6 @@ movement. Let's place this code at the end of the ``_process()`` function: .. tabs:: .. code-tab:: gdscript GDScript - # to allow the - - - if velocity.x != 0: $AnimatedSprite2D.animation = "walk" elif velocity.y != 0: From e1b2f0f4ca142754248d88f9547db1077bd0ceb4 Mon Sep 17 00:00:00 2001 From: Anas Mustafa <104536579+anasmustafa123@users.noreply.github.com> Date: Mon, 6 Oct 2025 13:10:50 +0300 Subject: [PATCH 3/4] Update getting_started/first_2d_game/03.coding_the_player.rst Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/first_2d_game/03.coding_the_player.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/getting_started/first_2d_game/03.coding_the_player.rst b/getting_started/first_2d_game/03.coding_the_player.rst index 591d20a28d2..0d6f51e894d 100644 --- a/getting_started/first_2d_game/03.coding_the_player.rst +++ b/getting_started/first_2d_game/03.coding_the_player.rst @@ -283,6 +283,7 @@ movement. Let's place this code at the end of the ``_process()`` function: $AnimatedSprite2D.flip_h = velocity.x < 0 if velocity.y != 0: $AnimatedSprite2D.flip_v = velocity.y > 0 + .. code-tab:: csharp if (velocity.X != 0) From 2df48fa2be21f6ea85bbffa2641c21c13db1a66b Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 6 Oct 2025 13:47:44 +0300 Subject: [PATCH 4/4] Allow the character to flip in both directions #11347 (c# code) --- .../first_2d_game/03.coding_the_player.rst | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/getting_started/first_2d_game/03.coding_the_player.rst b/getting_started/first_2d_game/03.coding_the_player.rst index 0d6f51e894d..26a1e4085b8 100644 --- a/getting_started/first_2d_game/03.coding_the_player.rst +++ b/getting_started/first_2d_game/03.coding_the_player.rst @@ -276,7 +276,7 @@ movement. Let's place this code at the end of the ``_process()`` function: elif velocity.y != 0: $AnimatedSprite2D.animation = "up" - # Allow the character to flip in both directions + # Allow the character to flip in both directions. if velocity.x != 0: # See the note below about the following boolean assignment. $AnimatedSprite2D.flip_v = false @@ -289,13 +289,22 @@ movement. Let's place this code at the end of the ``_process()`` function: if (velocity.X != 0) { animatedSprite2D.Animation = "walk"; + + } + else if (velocity.Y != 0) + { + animatedSprite2D.Animation = "up"; + } + + # Allow the character to flip in both directions. + if (velocity.X != 0) + { animatedSprite2D.FlipV = false; // See the note below about the following boolean assignment. animatedSprite2D.FlipH = velocity.X < 0; } - else if (velocity.Y != 0) + if (velocity.Y != 0) { - animatedSprite2D.Animation = "up"; animatedSprite2D.FlipV = velocity.Y > 0; }