Skip to main content

LookAt

A component that makes the current object's orientation follow a target's position or orientation.

TypeNameInterface Description
VariablesdirectionAim: LookAtDirection

Function: Gets the direction of the object that will point to the target.

VariablesdirectionUp: LookAtDirection

Function: Gets the direction of the object that will be aligned with the world up direction.

Variablesmode: LookAtMode

Function: Gets the mode for the look-at calculation.

VariablesoffsetRotation: Vector3f

Function: Gets An additional rotation applied after the look-at calculation. The value is in Euler angles.

Variablestarget: Transform | null

Function: Gets the transform of the target object to look at.

VariablesworldUp: LookAtWorldUp

Function: Gets the world-up vector for the look-at calculation.

Functionsconstructor()

Examples

constructor()

let obj = new APJS.LookAt();

Use Case

Object always faces the camera (billboard effect)

@component()
export class LookAtCamera extends APJS.BasicScriptComponent {
onUpdate(deltaTime: number): void {
const transform = this.getSceneObject().getTransform();
const children = this.getSceneObject().parent?.getChildren() || [];

// Find camera in scene
for (const child of this.getSceneObject().parent?.getChildren() || []) {
const cam = child.getComponent("Camera") as APJS.Camera;
if (cam) {
const camPos = child.getTransform().getWorldPosition();
const myPos = transform.getWorldPosition();
const dir = new APJS.Vector3f(
camPos.x - myPos.x,
0,
camPos.z - myPos.z
).normalize();
const angle = Math.atan2(dir.x, dir.z) * 180 / Math.PI;
transform.localEulerAngles = new APJS.Vector3f(0, angle, 0);
break;
}
}
}
}
Copyright © 2026 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalTerms of ServicePrivacy PolicyCookies