Skip to content

Follow target

Updated

Follow Target (comp-follow-target) keeps an entity placed relative to another one during play: a help panel that stays in front of the player, a pet that trails its owner, a label that hovers next to a moving machine. Unlike parenting, it does not copy every tiny movement. The follower waits until the target has moved or turned far enough, then glides smoothly to its new place. That makes floating panels comfortable to read, especially in VR where the head never holds perfectly still.

Follow Target is offered on groups, imported models, primitive meshes, image and video surfaces (image, GIF, SVG, KTX2, video, PDF, Lottie), text and 3D text, and UI layouts, lists and panels. It is not offered on cameras, lights, audio, floors and terrain, splats or navigation entities. To move several things together, put them under a group and give the group the Follow Target.

The target can be any entity or named object in the scene, including the player’s camera.

  1. On its first frame in play, the follower jumps to the target’s position plus offset, turned by rotationOffset. The offset is measured in the target’s own frame: { x: 0, y: 0, z: -1 } is one metre in front of it.
  2. It then anchors on the target’s pose and stays still while the target moves less than positionTolerance and turns less than angleTolerance.
  3. Once the target crosses either tolerance, the follower captures the target’s new pose and moves there smoothly over about smoothTime, then anchors again.
  4. With lockY, only the target’s heading (yaw) counts: when the player looks up or down, a panel stays level instead of tilting.

It does nothing in the editor, while disabled or inactive, or while its target cannot be found. Clearing target stops the follower where it is.

Prop Type Default Description
target string '' The entity id or object name to follow. From a script you may also pass the entity itself. Empty: it does not move.
offset { x, y, z } { x: 0, y: 0, z: -1 } Position relative to the target’s orientation, in metres.
rotationOffset { x, y, z } { x: 0, y: 0, z: 0 } Rotation relative to the target’s orientation, Euler radians.
lockY boolean true Ignore the target’s pitch and roll: the follower stays upright and only turns with the target’s heading.
positionTolerance number 0.25 How far, in metres, the target must move from the anchor before following starts.
angleTolerance number π/6 (30°) How far, in radians, the target must turn before following starts. Between 0 and π.
smoothTime number 0.35 Response time, in seconds. 0 moves at once.
Member What it does
setProps(patch) Change any prop. target accepts an id, a name, or the entity itself.
isFollowing true while the follower is gliding toward a new place. Read-only.
setPaused(paused) Pause or resume following, without disabling the component.
isPaused Whether it is paused. Read-only.
  • One driver per transform. Follow Target writes position and rotation directly (never scale). Do not combine it with another component that moves the same entity, such as a Motion Path, a Character Controller or an animation of its transform.
  • No physics on the follower. If the follower, one of its ancestors or one of its children has an enabled collider, rigid body, Character Controller or joint, Follow Target suspends itself. Remove or disable the physical components, or move the follower out of that hierarchy.
  • No self-chasing. A target that is the follower itself, or anything under it, is ignored.
  • Networking. On a networked copy that another client drives, the network’s transform wins.

1. A help panel that stays in front of the player

Section titled “1. A help panel that stays in front of the player”
HelpPanel.jx
#pragma lifecycle(startup)
function startup() {
// This script is on a UI Panel with a Follow Target component.
const follow = self.parent.getComponent(FollowTargetComponent);
const player = CameraDirector.main;
if (!player) return;
follow.setProps({
target: player,
offset: { x: 0, y: -0.2, z: -1.2 }, // a little low, 1.2 m ahead
lockY: true,
positionTolerance: 0.4,
angleTolerance: DEG_TO_RAD(35),
smoothTime: 0.5,
});
}

The panel follows the main camera entity. It sits 1.2 m in front and slightly below eye level, and with lockY it stays upright when the player looks up or down. The generous tolerances let the player glance around the panel without it chasing every head movement; it only moves when they walk away or turn more than 35°. DEG_TO_RAD converts degrees to the radians the prop expects.

2. A pet that trails its owner and sits on command

Section titled “2. A pet that trails its owner and sits on command”
Pet.jx
#pragma lifecycle(startup)
function startup() {
// The Pet group has a Follow Target whose target is 'Hero'.
const follow = self.parent.getComponent(FollowTargetComponent);
follow.setProps({ offset: { x: 0.8, y: 0, z: 1.2 }, smoothTime: 0.6 });
on('pet/sit', () => {
follow.setPaused(true);
log('Pet is sitting');
});
on('pet/come', () => {
follow.setPaused(false);
log('Pet is following');
});
}

A positive z offset puts the pet behind the hero (forward is -z), and x: 0.8 puts it to the hero’s right. A longer smoothTime makes it lag a little, like an animal catching up. setPaused(true) freezes it in place without losing its settings; setPaused(false) lets it rejoin.

3. A label that jumps to whatever the player selects

Section titled “3. A label that jumps to whatever the player selects”
InspectLabel.jx
#pragma lifecycle(startup)
function startup() {
const label = findEntity('Inspect Label');
const follow = label.getComponent(FollowTargetComponent);
const text = label.getComponent(TextComponent);
// Move the exhibits, so the label has something to keep up with.
const glide = { duration: 3, ease: Ease.InOutSine, repeat: Infinity, yoyo: true };
Tween.to(findEntity('Vase').position, { z: -1.5 }, glide);
Tween.to(findEntity('Bust').position, { y: 1.3 }, { ...glide, duration: 2 });
Tween.to(findEntity('Relic').position, { z: 1.5 }, { ...glide, duration: 4 });
on('exhibits', (event) => {
if (event.eventType === EventType.Selectable.Select) {
const exhibit = findEntity(event.entityId);
follow.setProps({
target: exhibit.entityId,
offset: { x: 0, y: 1.4, z: 0 },
lockY: true,
positionTolerance: 0.05, // metres it may lag before it follows
smoothTime: 0.2, // seconds to catch up
});
text.setProps({ text: exhibit.name });
label.setEnabled(true);
}
if (event.eventType === EventType.Selectable.Deselect) {
follow.setProps({ target: '' });
label.setEnabled(false);
}
});
}

When an exhibit is selected, the label’s target becomes that exhibit’s id and its text becomes the exhibit’s name; the label floats 1.4 m above it. When the selection clears, an empty target stops the follower and the label hides. The exhibits glide back and forth on endless tweens, and the label keeps up with the selected one without any per-frame code: it follows once the exhibit has moved positionTolerance from where the label last settled, then glides after it over about smoothTime. The defaults, 0.25 m and 0.35 s, suit a panel that should ignore small movements; for a label on a moving object, a small tolerance and a short smooth time keep it close behind while still easing every move.

FollowIndicator.jx
#pragma lifecycle(startup, update)
let follow;
let dot;
function startup() {
follow = findEntity('Help Panel').getComponent(FollowTargetComponent);
dot = findEntity('Moving Dot');
}
function update() {
const moving = follow.isFollowing && !follow.isPaused;
if (dot.visible !== moving) dot.visible = moving;
}

isFollowing is true only while the follower glides to a new place. The script shows a small dot during that glide, which is useful while tuning tolerances: if the dot flickers constantly, raise positionTolerance or angleTolerance.

  • The follower never moves. Check that target names an existing entity, and that neither the follower nor its parents or children carry physics components.
  • The panel tilts when the player looks down. Turn lockY on.
  • Offsets in the wrong direction. Offsets are in the target’s frame, where forward is -z. A negative z is in front.
  • Two components fight over the transform. Do not add Motion Path, a Character Controller or a transform animation to a follower.
  • Passing degrees to angleTolerance. It is in radians: use DEG_TO_RAD(30).