Skip to content

Commit 80ff166

Browse files
authored
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()`
2 parents 17903a7 + e289b92 commit 80ff166

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

getting_started/first_3d_game/03.player_movement_code.rst

+2
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ Here is the complete ``player.gd`` code for reference.
274274

275275
if direction != Vector3.ZERO:
276276
direction = direction.normalized()
277+
# Setting the basis property will affect the rotation of the node.
277278
$Pivot.basis = Basis.looking_at(direction)
278279

279280
# Ground Velocity
@@ -327,6 +328,7 @@ Here is the complete ``player.gd`` code for reference.
327328
if (direction != Vector3.Zero)
328329
{
329330
direction = direction.Normalized();
331+
// Setting the basis property will affect the rotation of the node.
330332
GetNode<Node3D>("Pivot").Basis = Basis.LookingAt(direction);
331333
}
332334

getting_started/first_3d_game/07.killing_player.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ Finally, the longest script, ``player.gd``:
349349
# Prevent diagonal moving fast af
350350
if direction != Vector3.ZERO:
351351
direction = direction.normalized()
352-
$Pivot.look_at(position + direction, Vector3.UP)
352+
# Setting the basis property will affect the rotation of the node.
353+
$Pivot.basis = Basis.looking_at(direction)
353354

354355
# Ground Velocity
355356
target_velocity.x = direction.x * speed
@@ -450,7 +451,8 @@ Finally, the longest script, ``player.gd``:
450451
if (direction != Vector3.Zero)
451452
{
452453
direction = direction.Normalized();
453-
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
454+
// Setting the basis property will affect the rotation of the node.
455+
GetNode<Node3D>("Pivot").Basis = Basis.LookingAt(direction);
454456
}
455457

456458
// Ground Velocity

getting_started/first_3d_game/09.adding_animations.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ Here's the *Player* script.
342342
# Prevent diagonal movement being very fast
343343
if direction != Vector3.ZERO:
344344
direction = direction.normalized()
345-
$Pivot.look_at(position + direction,Vector3.UP)
345+
# Setting the basis property will affect the rotation of the node.
346+
$Pivot.basis = Basis.looking_at(direction)
346347
$AnimationPlayer.speed_scale = 4
347348
else:
348349
$AnimationPlayer.speed_scale = 1
@@ -448,7 +449,8 @@ Here's the *Player* script.
448449
if (direction != Vector3.Zero)
449450
{
450451
direction = direction.Normalized();
451-
GetNode<Node3D>("Pivot").LookAt(Position + direction, Vector3.Up);
452+
// Setting the basis property will affect the rotation of the node.
453+
GetNode<Node3D>("Pivot").Basis = Basis.LookingAt(direction);
452454
GetNode<AnimationPlayer>("AnimationPlayer").PlaybackSpeed = 4;
453455
}
454456
else

0 commit comments

Comments
 (0)