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.
- Vector3.MODEL_FRONT is (0, 0, 1). Vector3.FORWARD is (0, 0, -1).
- look_at(target): the +Z front pointed straight away from the target (dot product -1.00), and 10 m became 15 m.
- look_at(target, Vector3.UP, true): dot 1.00, and 10 m became 5 m. A plain look_at followed by rotate_object_local(Vector3.UP, PI) gave the same, and so did face_point().
- A node that travels along -Z instead, aimed with a plain look_at: 10 m became 5 m. Plain look_at is right for things that face -Z.
- 8 swords in a ring of 3 m, each aimed at the same enemy: plain look_at, 0 of 8 facing it; face_point(), 8 of 8.
- A sword stretched to scale (1, 1, 3): look_at with use_model_front and face_point() both kept that scale, with the long axis toward the target.
- Straight up, look_at with use_model_front pointed the front at (0, 1, 0). face_point() gave (0, -1, 0) straight down and (0, 1, 0) straight up.
- Aiming along the velocity while hovering: look_at(global_position + velocity) with zero velocity printed the error "Node origin and target are in the same position, look_at() failed." and kept the old rotation. face_direction() with zero velocity returned false, kept the rotation and printed nothing.
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
- Turning smoothly instead of snapping: turn the short way around, or limit the turn rate for a homing sword.
- A spell that swings around when the caster turns: add it to the level, not the caster.
- Aiming at the mouse in 3D: find the point under the mouse first, then face it.
- Several swords around the player: space them evenly, then face each one at the enemy.
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
- A ball that hits the net however hard it is kicked
- A shot that meets a moving target
- An Area3D that does not see a bullet or another area
- A fire rate that holds at any frame rate
- FPS shots that land on the crosshair
- A spell that keeps flying straight after it leaves the hand
- Turn towards a target the short way round
- A laser beam that stops where it hits, the moment you aim
- Fast projectiles that never fly through enemies
- A trajectory line that matches where the ball lands
- Aim a spell at the mouse on a 3D floor
- A homing missile that turns, but not instantly
- Particles fall sideways when you rotate the emitter
- Particles that fly into the player
- Gaps in the trail of a fast emitter
- Make a tower shoot the enemy closest to your base
- Hit the target with an arcing shot at any angle and height
- Kick a RigidBody3D ball with the same strength at any tick rate
- Reload without losing or making up rounds
- Fan out any number of projectiles evenly around the aim direction
- Recoil that settles back to where the player aims