Skip to content

Transform constraints

Two engine components let one entity track another every frame, with no script — like Unity's LookAtConstraint and PositionConstraint:

  • Look At — rotate this entity to face a target.
  • Follow Target — move this entity to a target's position plus an offset.

Add them from the Inspector's Add Component menu. They run in the editor Play Mode, in standalone builds, and they compose — an entity can both follow and look at a target (a companion drone, a chase camera rig, a name-plate, a turret head).

Look At

Rotates the entity to point at the target entity each frame.

FieldMeaning
TargetThe entity to face.
Yaw onlyWhen on, only rotate around Y (stay upright) — good for characters and turrets. Off (default) is full 3D aim.
json
"lookAt": { "target": "player", "yawOnly": true }

Follow Target

Moves the entity to the target's position plus an offset each frame.

FieldMeaning
TargetThe entity to follow.
OffsetOffset from the target (the relativePosition field in JSON). Default [0, 0, 0].
AbsoluteOffset is in world space (on) vs rotated into the target's local frame (off, default — so an offset like "behind" stays behind as the target turns).
Follow rotationAlso copy the target's rotation. Default off.
Smoothing0 (default) snaps to the target each frame; > 0 is exponential smoothing — higher is snappier, lower lags more.
json
"followTarget": { "target": "player", "relativePosition": [2, 2.5, 2], "absolute": true, "smoothing": 6 }

Assigning the target

The Target field is a drop slot, just like a Unity object field. Set it either way:

  • Drag an entity from the Hierarchy onto the field, or
  • pick it from the field's dropdown.

Driving them from a script

The target and every field are plain component data, so a script can change them at runtime with setComponent — it merges a patch onto the current component, leaving the other fields untouched:

js
class Companion extends Behaviour {
  onStart() {
    // Start following whoever is closest, behind and above them.
    const player = this.players.getAll()[0]
    if (player) this.setComponent('followTarget', { target: player.id })
  }

  retarget(enemyId) {
    this.setComponent('lookAt', { target: enemyId })   // turn to face a new foe
    this.setComponent('followTarget', { smoothing: 10 }) // …and tighten the follow
  }
}

Use addComponent to add a constraint that wasn't there, removeComponent('lookAt') to drop it, and getComponent('followTarget') to read its current values (a snapshot — see Reading & writing components).

TIP

The Scripted Player example (?example=scriptedplayer) has a pink Companion drone that uses followTarget + lookAt to hover near the player and watch it — no script on the drone at all.