← Pixel Dreamer Studio

Point swords, projectiles and models that face +Z at the target

look_at turns -Z toward the target, like a camera. Imported models and many effects face +Z instead, so pass use_model_front = true.

Call look_at(target, Vector3.UP, true). The third argument, use_model_front, turns the node's +Z (Vector3.MODEL_FRONT) to the target instead of its -Z (Vector3.FORWARD). In our Godot 4.7 test an effect that flies along its own +Z at 5 m/s, aimed with a plain look_at from 10 m away, was 15 m away a second later. With use_model_front it was 5 m away, and a ring of 8 swords went from 0 of 8 facing the enemy to 8 of 8.

The code

Save it as face_target.gd. face_point() and face_direction() turn a node's +Z front toward a point or along a direction, keep its scale, pick another up vector when the target is straight above or below, and return false without touching the rotation when there is no direction, for example a sword hovering with zero velocity. front() tells you where a node's +Z points now. For example: const FaceTarget := preload("res://face_target.gd"), FaceTarget.face_point($Swords, enemy.global_position), or every physics frame FaceTarget.face_direction($Sword, velocity).

extends RefCounted
## Turn a model, effect or projectile whose front is +Z (Vector3.MODEL_FRONT, the way
## imported models and many effects face) toward a point or along a direction.


static func face_point(node: Node3D, target: Vector3) -> bool:
	return face_direction(node, target - node.global_position)


static func face_direction(node: Node3D, dir: Vector3) -> bool:
	if dir.length_squared() < 0.000001:
		return false  # no direction (standing still): keep the old rotation
	var up := Vector3.UP
	if absf(dir.normalized().dot(up)) > 0.999:
		up = Vector3.BACK  # straight up or down: any other up works
	var s := node.global_basis.get_scale()
	node.global_basis = Basis.looking_at(dir, up, true) * Basis.from_scale(s)
	return true


static func front(node: Node3D) -> Vector3:
	return (node.global_basis * Vector3.MODEL_FRONT).normalized()

What we measured

A Node3D at the origin and a target at (6, 0, 8), 10 m away. To stand in for an effect that travels along +Z, we moved the node along its own +Z at 5 m/s for one second in 60 steps. Two runs gave the same numbers.

Why it happens

In Godot, forward is -Z: Vector3.FORWARD is (0, 0, -1), a Camera3D looks down -Z, and look_at turns -Z toward the target. Models exported from tools like Blender arrive facing +Z, which Godot names Vector3.MODEL_FRONT, and effects built to travel forward along +Z do the same. A plain look_at turns their back to the target. look_at and Basis.looking_at take use_model_front for exactly this: true turns +Z to the target instead.

What to change

Swords to aim: Xianxia VFX has 37 cultivation effects for Godot 4, among them Flying Sword, Sword Rain, Sword Domain and Thousand Swords. Thousand Swords sends its swords along +Z and is a one-shot, so face it at the enemy with look_at(enemy.global_position, Vector3.UP, true) and then call play().

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Xianxia VFX has 37 cultivation effects for Godot 4, including Thousand Swords, which sends its swords along +Z: face it at the enemy and call play().

More how-tos for Xianxia VFX: Charge-up particles that fly in to the middle · orbit_velocity not working in 3D: use tangential_accel · Space flying swords, shields or orbs evenly around a character for any count

More how-tos: Projectiles and aiming