← Pixel Dreamer Studio

A homing missile that turns, but not instantly

Fixed speed, a turn rate, and a boost so it can never orbit its target.

Keep the speed fixed and turn the flight direction toward the target by at most the turn rate times delta each frame, with Vector3.rotated() around the cross product of the two directions. A missile that turns too slowly can circle a close target forever, so let the turn rate grow the longer it flies, and free it after a set life time.

A blue dot on a dark floor and a curved line of orange dots that bends to the right and ends at a red capsule, with a short gray dotted line for the capsule's own path
The script below in Godot 4.7, launched straight ahead at a target that moves to the side. Orange dots: the missile every 4 frames. Gray dots: the target. So the curve is easy to see, this shot uses a turn rate of 1.2 and a boost of 2. The defaults turn faster.

The code

Spawn the missile at the launcher, set target and velocity (the launch direction times the speed), then add it to the scene. Connect hit to your damage code. Put your missile mesh or effect under it as a child.

extends Node3D
## A homing missile: flies at a fixed speed and turns toward a moving target, a little at a time.
## Set target and velocity, then add it to the scene. It frees itself on a hit or when life runs out.

signal hit(target_node)

@export var speed := 12.0  # meters per second
@export var turn_rate := 3.0  # radians per second at launch
@export var turn_boost := 4.0  # more turn rate every second it flies, so it can never circle forever
@export var hit_radius := 0.5  # meters
@export var life := 4.0  # seconds

var target: Node3D
var velocity := Vector3.ZERO  # start direction from the launcher; empty = straight ahead
var _age := 0.0


func _ready() -> void:
	if velocity == Vector3.ZERO:
		velocity = -global_basis.z * speed


func _physics_process(delta: float) -> void:
	_age += delta
	if _age > life:
		queue_free()
		return
	if is_instance_valid(target):
		var to := target.global_position - global_position
		if to.length() <= hit_radius:
			hit.emit(target)
			queue_free()
			return
		var dir := velocity.normalized()
		var want := to.normalized()
		var angle := dir.angle_to(want)
		if angle > 0.0001:
			var axis := dir.cross(want)
			if axis.length() < 0.0001:
				axis = Vector3.UP  # target straight behind: pick a side to turn to
			var step := minf((turn_rate + turn_boost * _age) * delta, angle)
			dir = dir.rotated(axis.normalized(), step)
		velocity = dir * speed
	global_position += velocity * delta

We stepped the script frame by frame at 60 frames per second, so every run gives the same numbers. Launched straight ahead with the target 10 meters to the side, 90 degrees off, it hit after 1.03 seconds. A target 15 meters ahead running sideways at 5 meters per second was hit after 1.47 seconds. The speed stayed at exactly 12 meters per second on every frame.

Why it needs turn_boost

A missile with a fixed turn rate flies in a circle whose radius is its speed divided by the turn rate: 12 meters at 12 meters per second and 1 radian per second. With the target only 3 meters to its side, it never got closer than those 3 meters, and its life ran out at 4.02 seconds without a hit. With turn_boost at 4, the same missile hit after 1.45 seconds.

A target behind it, or a target that is gone

With the target 8 meters straight behind, the two directions point exactly apart and their cross product is zero, so there is no axis to turn around. The script then turns around the up axis, and the missile hit after 1.55 seconds.

If the target is freed in mid-flight, is_instance_valid() stops the steering. The missile keeps its direction and frees itself when its life runs out, at 4.02 seconds in our test.

What to change

Where it lands: spawn a hit effect at the impact point. Aim it first: aim a spell at the mouse on a 3D floor.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Projectile & Cast VFX for Godot 4 has Homing Orbs that curve in from different sides, and fires any of its 41 projectiles with fx.launch(enemy.global_position) and a hit signal when it lands.

More how-tos: Projectiles and aiming