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.
Before you start
Section titled “Before you start”- You should know how to find entities and change component props. See Working with entities.
- Follow Target writes the entity’s transform. Know which other components also move an entity; see Character Controller and Physics.
Where you can use it
Section titled “Where you can use it”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.
How following works
Section titled “How following works”- On its first frame in play, the follower jumps to the target’s position plus
offset, turned byrotationOffset. The offset is measured in the target’s own frame:{ x: 0, y: 0, z: -1 }is one metre in front of it. - It then anchors on the target’s pose and stays still while the target moves less than
positionToleranceand turns less thanangleTolerance. - Once the target crosses either tolerance, the follower captures the target’s new pose and moves there smoothly over about
smoothTime, then anchors again. - 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: - |
Position relative to the target’s orientation, in metres. |
rotation |
{ 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. |
position |
number | 0.25 |
How far, in metres, the target must move from the anchor before following starts. |
angle |
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. |
Scripting
Section titled “Scripting”| Member | What it does |
|---|---|
set |
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. |
set |
Pause or resume following, without disabling the component. |
isPaused |
Whether it is paused. Read-only. |
Rules to keep in mind
Section titled “Rules to keep in mind”- 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.
Examples
Section titled “Examples”1. A help panel that stays in front of the player
Section titled “1. A help panel that stays in front of the player”#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, });}A script points a UI panel’s Follow Target at the main camera, 1.2 m ahead and a little low, with tolerances that let you glance around before it glides back in front.
Drag to orbit the camera a little: the panel stays put. Turn further than 35° and it glides back in front of you.
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”#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 pet with a Follow Target trails a hero walking a circle; Sit pauses the follower where it stands and Come lets it catch up again.
Press Sit to stop the pet, and Come to let it run after the hero again. Drag to orbit the camera, scroll to zoom.
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”#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); } });}A text label with a Follow Target: selecting a moving exhibit retargets the follower to it and shows the exhibit's name; deselecting hides it.
Click an exhibit, then another, and watch the label follow it as it moves. Drag to orbit the camera, scroll to zoom.
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.
4. Show a “catching up” indicator
Section titled “4. Show a “catching up” indicator”#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;}A help panel follows the camera with a Follow Target; a script shows a green dot on it only while isFollowing says it is gliding to a new place.
Drag to orbit the camera beyond the panel’s tolerance: the green dot shows while the panel catches up. Scroll to zoom.
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.
Common mistakes
Section titled “Common mistakes”- The follower never moves. Check that
targetnames 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
lockYon. - Offsets in the wrong direction. Offsets are in the target’s frame, where forward is
-z. A negativezis 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: useDEG_TO_RAD(30).