From 482de629d94d787694638ff935e6717d8d73495e Mon Sep 17 00:00:00 2001 From: Alge Date: Wed, 26 Nov 2025 00:31:24 +1100 Subject: [PATCH] Update rotation + movement section of 2d_movement.rst to properly apply the movement in the direction the sprite is facing The code in the rotation + movement section was applying movement perpendicular to the up direction instead of in the direction the sprite is facing. This can be clearly seen in the animation. --- tutorials/2d/2d_movement.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorials/2d/2d_movement.rst b/tutorials/2d/2d_movement.rst index e012e063bf3..21b451d3789 100644 --- a/tutorials/2d/2d_movement.rst +++ b/tutorials/2d/2d_movement.rst @@ -124,7 +124,7 @@ while up/down moves it forward or backward in whatever direction it's facing. func get_input(): rotation_direction = Input.get_axis("left", "right") - velocity = transform.x * Input.get_axis("down", "up") * speed + velocity = transform.y * Input.get_axis("down", "up") * speed func _physics_process(delta): get_input() @@ -148,7 +148,7 @@ while up/down moves it forward or backward in whatever direction it's facing. public void GetInput() { _rotationDirection = Input.GetAxis("left", "right"); - Velocity = Transform.X * Input.GetAxis("down", "up") * Speed; + Velocity = Transform.Y * Input.GetAxis("down", "up") * Speed; } public override void _PhysicsProcess(double delta) @@ -162,7 +162,7 @@ while up/down moves it forward or backward in whatever direction it's facing. Here we've added two variables to track our rotation direction and speed. The rotation is applied directly to the body's ``rotation`` property. -To set the velocity, we use the body's ``transform.x`` which is a vector pointing +To set the velocity, we use the body's ``transform.y`` which is a vector pointing in the body's "forward" direction, and multiply that by the speed. Rotation + movement (mouse)