@@ -160,7 +160,11 @@ between ``-PI / 4`` radians and ``PI / 4`` radians.
160
160
func initialize(start_position, player_position):
161
161
# We position the mob by placing it at start_position
162
162
# and rotate it towards player_position, so it looks at the player.
163
- look_at_from_position(start_position, player_position, Vector3.UP)
163
+ #
164
+ # Ignore the player's height, so that the mob's orientation is not slightly
165
+ # shifted if the mob spawns while the player is jumping.
166
+ var target = Vector3(player_position.x, start_position.y, player_position.z)
167
+ look_at_from_position(start_position, target, Vector3.UP)
164
168
# Rotate this mob randomly within range of -45 and +45 degrees,
165
169
# so that it doesn't move directly towards the player.
166
170
rotate_y(randf_range(-PI / 4, PI / 4))
@@ -172,7 +176,11 @@ between ``-PI / 4`` radians and ``PI / 4`` radians.
172
176
{
173
177
// We position the mob by placing it at startPosition
174
178
// and rotate it towards playerPosition, so it looks at the player.
175
- LookAtFromPosition(startPosition, playerPosition, Vector3.Up);
179
+ //
180
+ // Ignore the player's height, so that the mob's orientation is not slightly
181
+ // shifted if the mob spawns while the player is jumping.
182
+ Vector3 target = new Vector3(player_position.x, start_position.y, player_position.z);
183
+ LookAtFromPosition(startPosition, target, Vector3.Up);
176
184
// Rotate this mob randomly within range of -45 and +45 degrees,
177
185
// so that it doesn't move directly towards the player.
178
186
RotateY((float)GD.RandRange(-Mathf.Pi / 4.0, Mathf.Pi / 4.0));
@@ -271,7 +279,11 @@ Here is the complete ``mob.gd`` script for reference.
271
279
func initialize(start_position, player_position):
272
280
# We position the mob by placing it at start_position
273
281
# and rotate it towards player_position, so it looks at the player.
274
- look_at_from_position(start_position, player_position, Vector3.UP)
282
+ #
283
+ # Ignore the player's height, so that the mob's orientation is not slightly
284
+ # shifted if the mob spawns while the player is jumping.
285
+ var target = Vector3(player_position.x, start_position.y, player_position.z)
286
+ look_at_from_position(start_position, target, Vector3.UP)
275
287
# Rotate this mob randomly within range of -45 and +45 degrees,
276
288
# so that it doesn't move directly towards the player.
277
289
rotate_y(randf_range(-PI / 4, PI / 4))
@@ -310,7 +322,11 @@ Here is the complete ``mob.gd`` script for reference.
310
322
{
311
323
// We position the mob by placing it at startPosition
312
324
// and rotate it towards playerPosition, so it looks at the player.
313
- LookAtFromPosition(startPosition, playerPosition, Vector3.Up);
325
+ //
326
+ // Ignore the player's height, so that the mob's orientation is not slightly
327
+ // shifted if the mob spawns while the player is jumping.
328
+ Vector3 target = new Vector3(player_position.x, start_position.y, player_position.z);
329
+ LookAtFromPosition(startPosition, target, Vector3.Up);
314
330
// Rotate this mob randomly within range of -45 and +45 degrees,
315
331
// so that it doesn't move directly towards the player.
316
332
RotateY((float)GD.RandRange(-Mathf.Pi / 4.0, Mathf.Pi / 4.0));
0 commit comments