Răsfoiți Sursa

Merge pull request #10829 from NNate1/getting-started-3d-game-character-consistent-orientation

[First 3D Game] Update player script recaps to use `Basis.looking_at()`
Matthew 3 luni în urmă
părinte
comite
80ff166341

+ 2 - 0
getting_started/first_3d_game/03.player_movement_code.rst

@@ -274,6 +274,7 @@ Here is the complete ``player.gd`` code for reference.
 
         if direction != Vector3.ZERO:
             direction = direction.normalized()
+            # Setting the basis property will affect the rotation of the node.
             $Pivot.basis = Basis.looking_at(direction)
 
         # Ground Velocity
@@ -327,6 +328,7 @@ Here is the complete ``player.gd`` code for reference.
             if (direction != Vector3.Zero)
             {
                 direction = direction.Normalized();
+                // Setting the basis property will affect the rotation of the node.
                 GetNode<Node3D>("Pivot").Basis = Basis.LookingAt(direction);
             }
 

+ 4 - 2
getting_started/first_3d_game/07.killing_player.rst

@@ -349,7 +349,8 @@ Finally, the longest script, ``player.gd``:
         # Prevent diagonal moving fast af
         if direction != Vector3.ZERO:
             direction = direction.normalized()
-            $Pivot.look_at(position + direction, Vector3.UP)
+            # Setting the basis property will affect the rotation of the node.
+            $Pivot.basis = Basis.looking_at(direction)
 
         # Ground Velocity
         target_velocity.x = direction.x * speed
@@ -450,7 +451,8 @@ Finally, the longest script, ``player.gd``:
             if (direction != Vector3.Zero)
             {
                 direction = direction.Normalized();
-                GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
+                // Setting the basis property will affect the rotation of the node.
+                GetNode<Node3D>("Pivot").Basis = Basis.LookingAt(direction);
             }
 
             // Ground Velocity

+ 4 - 2
getting_started/first_3d_game/09.adding_animations.rst

@@ -342,7 +342,8 @@ Here's the *Player* script.
         # Prevent diagonal movement being very fast
         if direction != Vector3.ZERO:
             direction = direction.normalized()
-            $Pivot.look_at(position + direction,Vector3.UP)
+            # Setting the basis property will affect the rotation of the node.
+            $Pivot.basis = Basis.looking_at(direction)
             $AnimationPlayer.speed_scale = 4
         else:
             $AnimationPlayer.speed_scale = 1
@@ -448,7 +449,8 @@ Here's the *Player* script.
             if (direction != Vector3.Zero)
             {
                 direction = direction.Normalized();
-                GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
+                // Setting the basis property will affect the rotation of the node.
+                GetNode<Node3D>("Pivot").Basis = Basis.LookingAt(direction);
                 GetNode<AnimationPlayer>("AnimationPlayer").PlaybackSpeed = 4;
             }
             else