Skip to content

Transform constraints ​

Two engine components let one entity track another every frame, with no script:

  • 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 in published multiplayer, 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).

A constraint on a Camera entity moves the view only where that entity drives it: in the play-test and standalone builds with the built-in player turned off. With the built-in player its follow camera drives the view, and a multiplayer room reads the main camera's pose once, when it loads; there, move the camera from a client script (see The gameplay camera).

Look At ​

Turns the entity's front toward the target entity each frame: its +Z, the front of a model, or for a Camera entity its view (−Z).

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": "<entity id>", "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). [0, 0, 0] when the field is absent; added from the Inspector it starts at [0, 2, -4].
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": "<entity id>", "relativePosition": [2, 2.5, 2], "absolute": true, "smoothing": 6 }

Assigning the target ​

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

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

The target is an entity id. A player id from players.* (player.id) names a player, not an entity, so it is not a target.

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 the Hero object.
    const hero = this.game.findEntity('Hero')
    if (hero) this.setComponent('followTarget', { target: hero.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.