@@ -139,7 +139,8 @@ call its ``normalized()`` method.
139139
140140 if direction != Vector3.ZERO:
141141 direction = direction.normalized()
142- $Pivot.look_at(position + direction, Vector3.UP)
142+ # Setting the basis property will affect the rotation of the node.
143+ $Pivot.basis = Basis.looking_at(direction)
143144
144145 .. code-tab :: csharp
145146
@@ -150,26 +151,16 @@ call its ``normalized()`` method.
150151 if (direction != Vector3.Zero)
151152 {
152153 direction = direction.Normalized();
153- GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
154+ // Setting the basis property will affect the rotation of the node.
155+ GetNode<Node3D>("Pivot").Basis = Basis.LookingAt(direction);
154156 }
155157 }
156158
157159Here, we only normalize the vector if the direction has a length greater than
158160zero, which means the player is pressing a direction key.
159161
160- In this case, we also get the ``Pivot `` node and call its ``look_at() `` method.
161- This method takes a position in space to look at in global coordinates and the
162- up direction. In this case, we can use the ``Vector3.UP `` constant.
163-
164- .. note ::
165-
166- A node's local coordinates, like ``position ``, are relative to their
167- parent. Global coordinates, like ``global_position `` are relative to the world's main axes you can see
168- in the viewport instead.
169-
170- In 3D, the property that contains a node's position is ``position ``. By
171- adding the ``direction `` to it, we get a position to look at that's one meter
172- away from the ``Player ``.
162+ We compute the direction the ``$Pivot `` is looking by creating a :ref: `Basis <class_Basis >`
163+ that looks in the ``direction `` direction.
173164
174165Then, we update the velocity. We have to calculate the ground velocity and the
175166fall speed separately. Be sure to go back one tab so the lines are inside the
@@ -274,7 +265,7 @@ Here is the complete ``Player.gd`` code for reference.
274265
275266 if direction != Vector3.ZERO:
276267 direction = direction.normalized()
277- $Pivot.look_at(position + direction, Vector3.UP )
268+ $Pivot.basis = Basis.looking_at(direction )
278269
279270 # Ground Velocity
280271 target_velocity.x = direction.x * speed
@@ -327,7 +318,7 @@ Here is the complete ``Player.gd`` code for reference.
327318 if (direction != Vector3.Zero)
328319 {
329320 direction = direction.Normalized();
330- GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up );
321+ GetNode<Node3D>("Pivot").Basis = Basis.LookingAt(direction );
331322 }
332323
333324 // Ground velocity
0 commit comments