Skip to content
Camera

Gameplay / Camera

Camera Class

Camera


Camera Object defines the view of the 3D game world.

Camera Where is the location?

In an instance of the game, each client has its own Camera object associated with it. The camera object only exists on the viewer's client and resides locally, so it cannot be edited directly from the server.

Each client's specific Camera object can be accessed through the Camera.current Camera property on that client.

Camera How does the object work?

The attributes of the camera define the current view of the 3D game world. The most important of these is:

  • Camera.currentCamera.worldTransform Indicate the position and orientation of the camera.

  • Camera.currentCamera.rotationMode Adjust the rotation mode of the camera based on its attributes, including whether it rotates with the character, whether the camera remains fixed without rotation, and whether it can be controlled by the right mouse button. Camera.currentCamera.positionMode property adjust the position mode of the camera.

  • Camera.currentCamera.fov Indicates the visible range of the observable world.

Hierarchy

Table of contents

Properties

onSwitchComplete: MulticastDelegate<() => void> other
Callback completed by switching cameras
springArm: SpringArm other
Spring arm
click

Properties

onBeforeDestroyDelegate: MulticastDelegate<() => void> other
Event callback before object destruction
onCustomPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Monitor custom attribute synchronization events
onDestroyDelegate: MulticastDelegate<() => void> other
Event callback after object destruction
onPropertyChange: Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>>
Monitor system replicated events

Accessors

downAngleLimit(): number other
Get camera downward angle limit
fadeObstructionEnabled(): boolean other
Get whether the transparency effect is enable
fadeObstructionOpacity(): number other
Obtain transparency
fixedElevation(): boolean other
Fixed camera height
fov(): number other
Get camera field of view
maxLagDistance(): number other
Position maximum delay distance
positionLagEnabled(): boolean other
Enable position Delay
positionLagSpeed(): number other
Position delay speed
positionMode(): CameraPositionMode other
Position mode
preset(value: CameraPreset): void
Set camera Presets
rotationLagEnabled(): boolean other
Enable Rotation Delay
rotationLagSpeed(): number other
Rotation delay speed
rotationMode(): CameraRotationMode other
Rotate mode
upAngleLimit(): number other
Upward angle limitation
currentCamera(): Camera other
Current camera
click

Accessors

actorFlagValue(): number other
Get object tags
actorLevel(): number other
Obtain Actor Level
assetId(): string other
Retrieve the UID of the resource currently being used by the object
gameObjectId(): string other
Get the unique identification of an object (a string that uniquely identifies an object).
isDestroyed(): boolean other
Has the current object been destroyed
isReady(): boolean other
Current object status
localTransform(): Transform other
Local transformation of the current object
name(): string other
Return the current object name
netStatus(): NetStatus other
Get the current object synchronization status
parent(): GameObject other
Retrieve the current parent object
tag(): string other
Get the tag of the current object
worldTransform(): Transform other
Current object world transformation

Methods

lock(target: GameObject, val?: Object): void other
Camera locks target
lookAt(target: GameObject Vector): void other
Camera towards target
unlock(): void other
Unlock target
shake([shake](mw.Camera.md#shake)Info, duration?: number): void other
Start camera shake
stopShake(): void other
Stop camera shake
switch(newCamera: Camera, blendTime?: number, blendFunc?: CameraSwitchBlendFunction, blendExp?: number): Camera other
Switch camera
click

Methods

addComponent<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>, bInReplicates?: boolean): T: extends Script<T> other
Add a script component
asyncGetChildByName(name: string): Promise<GameObject> other
Asynchronous search for sub objects based on their names
asyncReady(): Promise<GameObject> other
Return after the object is ready
clone(gameObjectInfo?: GameObjectInfo): GameObject other
Copy Objects
destroy(): void other
delete object
getBoundingBox(nonColliding?: boolean, includeFromChild?: boolean, outer?: Vector): Vector other
Get the size of the object's bounding box
getBounds(onlyCollidingComponents: boolean, originOuter: Vector, boxExtentOuter: Vector, includeFromChild?: boolean): void other
Obtain object boundaries
getChildByGameObjectId(gameObjectId: string): GameObject other
Search for sub objects based on gameObjectid
getChildByName(name: string): GameObject other
Search for sub objects by name
getChildByPath(path: string): GameObject other
Find sub objects according to path
getChildren(): GameObject[] other
Obtain sub objects
getChildrenBoundingBoxCenter(outer?: Vector): Vector other
Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0])
getChildrenByName(name: string): GameObject[] other
Search for all sub objects by name
getComponent<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T> other
Get the component of the specified type
getComponentPropertys<T: extends Script<T>>(constructor: (...args: unknown[]) => T: extends Script<T>): Map<string, IPropertyOptions> other
Get property of script component
getComponents<T: extends Script<T>>(constructor?: (...args: unknown[]) => T: extends Script<T>): T: extends Script<T>[] other
Get all component of the specified type
getCustomProperties(): string[] other
Get all customize property
getCustomProperty<T: extends CustomPropertyType>(propertyName: string): T: extends CustomPropertyType other
Get customize property
getCustomPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getPropertyChangeDelegate(property): Readonly<MulticastDelegate<(path: string, value: unknown, oldValue: unknown) => void>> other
Event proxy triggered when a given object property is modified
getVisibility(): boolean other
Obtain whether the object is displayed
isPrefabActor(): boolean other
Return whether the current object is a prefabricated body
moveBy(velocity: Vector, isLocal?: boolean): void other
Smoothly move an object over time according to a given velocity vector
moveTo(targetPosition: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly move from the current position to the target position within the specified time
rotateBy(rotation: Quaternion Rotation, multiplier: number, isLocal?: boolean): void other
Rotate the object smoothly over time according to the given rotation amount
rotateTo(targetRotation: Quaternion Rotation, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current rotation to the target rotation within the specified time
scaleBy(scale: Vector, isLocal?: boolean): void other
Smoothly scale objects over time using a given scaling vector per second
scaleTo(targetScale: Vector, time: number, isLocal?: boolean, onComplete?: () => void): void other
Smoothly changes from the current scale to the target scale within the specified time
setAbsolute(absolutePosition?: boolean, absoluteRotation?: boolean, absoluteScale?: boolean): void other
Set whether the object localTransform is relative to the parent object or the world
setCustomProperty(propertyName: string, value: undefined CustomPropertyType): void other
Set custom attributes
setVisibility(status: boolean PropertyStatus, propagateToChildren?: boolean): void other
Set whether the object is displayed
stopMove(): void other
Interrupt further movement of moveTo() and moveBy()
stopRotate(): void other
Interrupt further rotation from rotateTo() or rotateBy()
stopScale(): void other
Interrupt further scale from ScaleTo() or ScaleBy()
asyncFindGameObjectById(gameObjectId: string): Promise<GameObject> other
Asynchronous search for GameObject through gameObjectid
asyncGetGameObjectByPath(path: string): Promise<GameObject> other
Asynchronously find objects through path
asyncSpawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): Promise<T: extends GameObject<T>> other
Asynchronous construction of an object
bulkPivotTo(gameObjects: GameObject[], transforms: Transform[]): void other
Batch set position
findGameObjectById(gameObjectId: string): GameObject other
Search for objects through gameObjectid
findGameObjectByName(name: string): GameObject other
Search for objects by name
findGameObjectsByName(name: string): GameObject[] other
Search for objects by name
findGameObjectsByTag(tag: string): GameObject[] other
Get objects through customize tag
getGameObjectByPath(path: string): GameObject other
Search for objects through paths
spawn<T: extends GameObject<T>>(assetId: string, gameObjectInfo?: GameObjectInfo): T: extends GameObject<T> other
Construct an object

Properties


onSwitchComplete

onSwitchComplete: MulticastDelegate<() => void> other

Callback completed by switching cameras

Precautions

Switch to the current camera to complete the binding function

Usage example: create a script named "CameraExample", place it in the object bar, open the script, enter the following code to save, run the game, and randomly create 5 camera in the scene. Press keyboard "1" to switch cameras. Press keyboard "2" to switch back to the default camera. You will see the effect of camera switching in the scene. The code is as follows:

ts
@Component
export default class CameraExample extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current camera
            let myCamera = Camera.currentCamera;
            let curCameraIndex = -1;
            // Create 5 camera randomly in the scene
            let cameraArray = new Array<Camera>();
            for (let i = 0;
i < 5;
i++) {
                let camera = GameObject.spawn<Camera>("Camera") as Camera;
                camera.worldTransform.position = new Vector(MathUtil.randomInt(-1000, 1000), MathUtil.randomInt(-1000, 1000),MathUtil.randomInt(0, 1000));
                camera.worldTransform.rotation = new Rotation(MathUtil.randomInt(-90, 90), MathUtil.randomInt(-30, 30),MathUtil.randomInt(-150, 150));
                cameraArray.push(camera);
                camera.onSwitchComplete.add(() => {
                    Console.log ("current camera serial number"+i);
                    curCameraIndex = i;
                });
            }
            // Add a key method: press the keyboard "1" to switch the camera
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Switch Camera");
                let newCamera = (curCameraIndex + 1) % 5;
                Camera.switch(cameraArray[newCamera], 5, CameraSwitchBlendFunction.Linear);
            });
            // Add a key method: press "2" on the keyboard to switch back to the default camera
            InputUtil.onKeyDown(Keys.Two, () => {
                console.log("Switch Default Camera");
                Camera.switch(myCamera);
            });
        }
    }
}
@Component
export default class CameraExample extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current camera
            let myCamera = Camera.currentCamera;
            let curCameraIndex = -1;
            // Create 5 camera randomly in the scene
            let cameraArray = new Array<Camera>();
            for (let i = 0;
i < 5;
i++) {
                let camera = GameObject.spawn<Camera>("Camera") as Camera;
                camera.worldTransform.position = new Vector(MathUtil.randomInt(-1000, 1000), MathUtil.randomInt(-1000, 1000),MathUtil.randomInt(0, 1000));
                camera.worldTransform.rotation = new Rotation(MathUtil.randomInt(-90, 90), MathUtil.randomInt(-30, 30),MathUtil.randomInt(-150, 150));
                cameraArray.push(camera);
                camera.onSwitchComplete.add(() => {
                    Console.log ("current camera serial number"+i);
                    curCameraIndex = i;
                });
            }
            // Add a key method: press the keyboard "1" to switch the camera
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Switch Camera");
                let newCamera = (curCameraIndex + 1) % 5;
                Camera.switch(cameraArray[newCamera], 5, CameraSwitchBlendFunction.Linear);
            });
            // Add a key method: press "2" on the keyboard to switch back to the default camera
            InputUtil.onKeyDown(Keys.Two, () => {
                console.log("Switch Default Camera");
                Camera.switch(myCamera);
            });
        }
    }
}

springArm

springArm: SpringArm other

Spring arm

Precautions

The camera system consists of a spring arm and a camera. The actual mounting point is the spring arm, while the camera is mounted at the end of the spring arm.

Usage example: drag the used asset: "26950" into the priority loading column to create a script named "Camera_SpringArm", place it in the object column, open the script, enter the following code to save, run the game, and you will generate 10 columns in the scene to trigger the collision of the camera spring bar. press the keyboard "1", enable/disable the collision of the camera spring bar, press the keyboard "2", enable/disable the collision detection of camera spring bar movement. You can see the different effects of disabling these attributes. The code is as follows:

ts
@Component
export default class Camera_SpringArm extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        if(SystemUtil.isServer()) {
            // Generate 10 pillars for camera spring rod collision
            for (let i = 0;
i < 10;
i++) {
                GameObject.spawn<Model>("26950",{transform: new Transform(new Vector(100, i * 100, 0), Rotation.zero, Vector.one)});
            }
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Add a button method: Press keyboard "1" to enable/disable camera spring rod collision
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.springArm.collisionEnabled = !myCamera.springArm.collisionEnabled;
                Console.log ("collision of camera spring arm"+myCamera.springArm. collisionEnabled);
            });
            // Add a key method: press the keyboard "2", enable/disable the collision detect of camera spring bar movement
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.collisionEnabled = !myCamera.springArm.collisionEnabled;
                Console.log ("Camera Spring Arm Movement Collision Detection"+myCamera. springArm. collisionEnabled);
            });
        }
    }
}
@Component
export default class Camera_SpringArm extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        if(SystemUtil.isServer()) {
            // Generate 10 pillars for camera spring rod collision
            for (let i = 0;
i < 10;
i++) {
                GameObject.spawn<Model>("26950",{transform: new Transform(new Vector(100, i * 100, 0), Rotation.zero, Vector.one)});
            }
        }
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Add a button method: Press keyboard "1" to enable/disable camera spring rod collision
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.springArm.collisionEnabled = !myCamera.springArm.collisionEnabled;
                Console.log ("collision of camera spring arm"+myCamera.springArm. collisionEnabled);
            });
            // Add a key method: press the keyboard "2", enable/disable the collision detect of camera spring bar movement
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.collisionEnabled = !myCamera.springArm.collisionEnabled;
                Console.log ("Camera Spring Arm Movement Collision Detection"+myCamera. springArm. collisionEnabled);
            });
        }
    }
}

Accessors


downAngleLimit

get downAngleLimit(): number other

set downAngleLimit(value): void other

Get camera downward angle limit

Precautions

When the camera rotates downward, the maximum angle range is 0-90.

Usage example: create a script named "Example_Camera_DownAngleLimit", place it in the object bar, open the script, enter the following code to save, run the game, set the camera angle limit, and set the maximum upward angle to 30, and the maximum downward rotation angle to 10. You will see the effect of limited camera rotation in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_DownAngleLimit extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}
@Component
export default class Example_Camera_DownAngleLimit extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}

Returns

number

Set camera downward angle limit

Precautions

When the camera rotates downward, the maximum angle range is 0-90.

Parameters

value numberAngle limitation

fadeObstructionEnabled

get fadeObstructionEnabled(): boolean other

set fadeObstructionEnabled(value): void other

Get whether the transparency effect is enable

Precautions

Objects entering the range of spring arm will be transparent, and redo after leaving

Returns

boolean

Set whether to enable transparency effect

Precautions

Objects entering the range of spring arm will be transparent, and redo after leaving

Parameters

valueboolean

fadeObstructionOpacity

get fadeObstructionOpacity(): number other

set fadeObstructionOpacity(value): void other

Obtain transparency

Precautions

Range 0-1, the larger the value, the higher the transparency. 1 is completely transparent

Usage example: create a script named "Example_Camera_FixedElevation", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", fix the height of the camera, and jump. You will see the effect that the camera follows the height of the character when the character jumps in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_FixedElevation extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable transparency effect
            myCamera.transparencyEnabled = true;
            // Add a button method: Press keyboard "1" to increase transparency
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.transparency += 0.1;
            });
            // Add a button method: Press and hold the keyboard "2" to reduce transparency
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.transparency -= 0.1;
            });
        }
    }
}
@Component
export default class Example_Camera_FixedElevation extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable transparency effect
            myCamera.transparencyEnabled = true;
            // Add a button method: Press keyboard "1" to increase transparency
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.transparency += 0.1;
            });
            // Add a button method: Press and hold the keyboard "2" to reduce transparency
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.transparency -= 0.1;
            });
        }
    }
}

Returns

number

Set transparency

Precautions

Range 0-1, the larger the value, the higher the transparency. 1 is completely transparent

Parameters

valuenumber

fixedElevation

get fixedElevation(): boolean other

set fixedElevation(value): void other

Fixed camera height

Precautions

The z-axis value of the camera position will not be changed no matter how the hanging point is moved.

Usage example: create a script named "Example_Camera_FixedElevation", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", fix the height of the camera, and jump. You will see the effect that the camera follows the height of the character when the character jumps in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_FixedElevation extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}
@Component
export default class Example_Camera_FixedElevation extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}

Returns

boolean

Fixed camera height

Precautions

The z-axis value of the camera position will not be changed no matter how the hanging point is moved.

Parameters

value booleanIs it fixed

fov

get fov(): number other

set fov(value): void other

Get camera field of view

Precautions

FOV, That is, the horizontal visual field angle in perspective mode. The larger the FOV, the larger the visual field angle

Example usage: Create a script called "Instance_Camera_FOV", place it in the object bar, open the script, enter the following code to save, run the game, hold down the keyboard "2" to increase the camera FOV, and hold down the keyboard "3" to decrease the camera FOV. You will see the effect of camera FOV changes in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_FOV extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}
@Component
export default class Example_Camera_FOV extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}

Returns

number

Set camera field of view

Precautions

FOV, That is, the horizontal visual field angle in perspective mode. The larger the FOV, the larger the visual field angle

Parameters

value numberfield

maxLagDistance

get maxLagDistance(): number other

set maxLagDistance(value): void other

Position maximum delay distance

Precautions

The maximum distance between the camera and the hanging point when the control character moves

Example usage: Create a script called "Instance_Camera_MaxLagDistance", place it in the object bar, open the script, enter the following code to save, run the game, enable position delay, and set the maximum position delay distance to 200. You will see the effect of the camera position delay in the scene, where the farthest camera delay is only 200cm. The code is as follows:

ts
@Component
export default class Example_Camera_MaxLagDistance extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
        }
    }
}
@Component
export default class Example_Camera_MaxLagDistance extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
        }
    }
}

Returns

number

Position maximum delay distance

Precautions

The maximum distance between the camera and the hanging point when the control character moves

Parameters

value numberMaximum delay distance

positionLagEnabled

get positionLagEnabled(): boolean other

set positionLagEnabled(value): void other

Enable position Delay

Precautions

When a person moves when the camera is turned on, the movement of the camera following the person will be delayed. When the camera is turned off, there will be no delay effect

Example usage: Create a script called "Instance_Camera_PositionLagEnabled", place it in the object bar, open the script, enter the following code to save, run the game, and you will see the effect of camera position delay in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_PositionLagEnabled extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}
@Component
export default class Example_Camera_PositionLagEnabled extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}

Returns

boolean

Enable position Delay

Precautions

When a person moves when the camera is turned on, the movement of the camera following the person will be delayed. When the camera is turned off, there will be no delay effect

Parameters

value booleanIs it enabled

positionLagSpeed

get positionLagSpeed(): number other

set positionLagSpeed(value): void other

Position delay speed

Precautions

Control the speed at which the camera reaches the position of the target when the character moves

Usage example: create a script named "Example_Camera_PositionLagSpeed", place it in the object bar, open the script, enter the following code to save, run the game, set the redo speed of the position delay to 1 after the position delay is enabled, and you will see the effect of the camera slowly recovering the position after the position delay of the camera in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_PositionLagSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}
@Component
export default class Example_Camera_PositionLagSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}

Returns

number

Set camera position delay speed

Precautions

Control the speed at which the camera reaches the position of the target when the character moves

Parameters

value numberDelay speed

positionMode

get positionMode(): CameraPositionMode other

set positionMode(value): void other

Position mode

Precautions

Camera position mode. Fixed mode: the camera is fixed in a position and cannot be moved. Follow mode: the camera follows an object (the character is the default) and moves all the time.

Usage example: create a script named "Example_Camera_PositionMode", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "2", and switch the position mode of the camera. You will see the effects of different camera position modes in the scene and the printed current camera position mode on the console. The code is as follows:

ts
@Component
export default class Example_Camera_PositionMode extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Print the position mode and rotation mode of the current character camera
            Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            let preset = 0;
            // Add a key method: press "1" on the keyboard to switch camera presets
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.preset = (preset + 1) % 6;
                Console.log ("current character camera preset"+CameraPreset [preset]);
                preset++;
            });
            // Add a key method: press "2" on the keyboard to switch the position mode of the camera
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.positionMode = (myCamera.positionMode + 1) % 2;
                Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            });
            // Add a key method: press "3" on the keyboard to switch the rotation mode of the camera
            InputUtil.onKeyDown(Keys.Three, () => {
                myCamera.rotationMode = (myCamera.rotationMode + 1) % 3;
                Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            });
        }
    }
}
@Component
export default class Example_Camera_PositionMode extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Print the position mode and rotation mode of the current character camera
            Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            let preset = 0;
            // Add a key method: press "1" on the keyboard to switch camera presets
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.preset = (preset + 1) % 6;
                Console.log ("current character camera preset"+CameraPreset [preset]);
                preset++;
            });
            // Add a key method: press "2" on the keyboard to switch the position mode of the camera
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.positionMode = (myCamera.positionMode + 1) % 2;
                Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            });
            // Add a key method: press "3" on the keyboard to switch the rotation mode of the camera
            InputUtil.onKeyDown(Keys.Three, () => {
                myCamera.rotationMode = (myCamera.rotationMode + 1) % 3;
                Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            });
        }
    }
}

Returns

CameraPositionMode

Position mode

Precautions

Camera position mode. Fixed mode: the camera is fixed in a position and cannot be moved. Follow mode: the camera follows an object (the character is the default) and moves all the time.

Parameters

value CameraPositionModePosition mode

preset

set preset(value): void

Set camera Presets

Precautions

The camera provides a preset viewing angle mode. First person, third person, overhead angle, default, TPS over shoulder angle, FPS shoot angle.

Example usage: Create a script called "Camera_Reset", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", and switch camera presets. You will see the effect of different camera presets in the scene. The code is as follows:

ts
@Component
export default class Camera_Preset extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Print the position mode and rotation mode of the current character camera
            Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            let preset = 0;
            // Add a key method: press "1" on the keyboard to switch camera presets
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.preset = (preset + 1) % 6;
                Console.log ("current character camera preset"+CameraPreset [preset]);
                preset++;
            });
            // Add a key method: press "2" on the keyboard to switch the position mode of the camera
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.positionMode = (myCamera.positionMode + 1) % 2;
                Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            });
            // Add a key method: press "3" on the keyboard to switch the rotation mode of the camera
            InputUtil.onKeyDown(Keys.Three, () => {
                myCamera.rotationMode = (myCamera.rotationMode + 1) % 3;
                Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            });
        }
    }
}
@Component
export default class Camera_Preset extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Print the position mode and rotation mode of the current character camera
            Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            let preset = 0;
            // Add a key method: press "1" on the keyboard to switch camera presets
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.preset = (preset + 1) % 6;
                Console.log ("current character camera preset"+CameraPreset [preset]);
                preset++;
            });
            // Add a key method: press "2" on the keyboard to switch the position mode of the camera
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.positionMode = (myCamera.positionMode + 1) % 2;
                Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            });
            // Add a key method: press "3" on the keyboard to switch the rotation mode of the camera
            InputUtil.onKeyDown(Keys.Three, () => {
                myCamera.rotationMode = (myCamera.rotationMode + 1) % 3;
                Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            });
        }
    }
}

Parameters

value CameraPresetPreset

rotationLagEnabled

get rotationLagEnabled(): boolean other

set rotationLagEnabled(value): void other

Enable Rotation Delay

Precautions

When the camera is turned on, the movement of the camera following the character is delayed. When the camera is turned off, there is no delay effect

Usage example: create a script named "Example_Camera_RotationLagEnabled", place it in the object bar, open the script, enter the following code to save, run the game, and turn on the camera rotation delay. You will see the effect of the delay when the camera rotates in the scene. The code is as follows:

ts
@Component
export default class RotationLagEnabled extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}
@Component
export default class RotationLagEnabled extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}

Returns

boolean

Enable Rotation Delay

Precautions

When the camera is turned on, the movement of the camera following the character is delayed. When the camera is turned off, there is no delay effect

Parameters

value booleanIs it enabled

rotationLagSpeed

get rotationLagSpeed(): number other

set rotationLagSpeed(value): void other

Rotation delay speed

Precautions

Control the angular velocity at which the camera reaches the target position while rotating the viewpoint

Usage example: create a script named "Example_Camera_RotationLagSpeed", place it in the object bar, open the script, enter the following code to save, run the game, and turn on the camera rotation delay. You will see the effect of the delay when the camera rotates in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_RotationLagSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}
@Component
export default class Example_Camera_RotationLagSpeed extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}

Returns

number

Rotation delay speed

Precautions

Control the angular velocity at which the camera reaches the target position while rotating the viewpoint

Parameters

value numberDelay speed

rotationMode

get rotationMode(): CameraRotationMode other

set rotationMode(value): void other

Rotate mode

Precautions

Camera rotation mode. Fixed orientation: The camera is fixed in a certain direction. Follow direction: The camera follows the direction of the target face. Control orientation: the orientation of the camera is controlled by the input control.

Usage example: create a script named "Example_Camera_RotationMode", place it in the object bar, open the script, enter the following code to save, run the game, press "3" on the keyboard, and switch the rotation mode of the camera. You will see the effects of different rotation modes of the camera in the scene and the current rotation mode of the printed camera on the console. The code is as follows:

ts
@Component
export default class Example_Camera_RotationMode extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Print the position mode and rotation mode of the current character camera
            Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            let preset = 0;
            // Add a key method: press "1" on the keyboard to switch camera presets
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.preset = (preset + 1) % 6;
                Console.log ("current character camera preset"+CameraPreset [preset]);
                preset++;
            });
            // Add a key method: press "2" on the keyboard to switch the position mode of the camera
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.positionMode = (myCamera.positionMode + 1) % 2;
                Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            });
            // Add a key method: press "3" on the keyboard to switch the rotation mode of the camera
            InputUtil.onKeyDown(Keys.Three, () => {
                myCamera.rotationMode = (myCamera.rotationMode + 1) % 3;
                Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            });
        }
    }
}
@Component
export default class Example_Camera_RotationMode extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Retrieve the character currently controlled by the player
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Print the position mode and rotation mode of the current character camera
            Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            let preset = 0;
            // Add a key method: press "1" on the keyboard to switch camera presets
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.preset = (preset + 1) % 6;
                Console.log ("current character camera preset"+CameraPreset [preset]);
                preset++;
            });
            // Add a key method: press "2" on the keyboard to switch the position mode of the camera
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.positionMode = (myCamera.positionMode + 1) % 2;
                Console.log ("position mode of the current character camera"+CameraPositionMode [myCamera. positionMode]);
            });
            // Add a key method: press "3" on the keyboard to switch the rotation mode of the camera
            InputUtil.onKeyDown(Keys.Three, () => {
                myCamera.rotationMode = (myCamera.rotationMode + 1) % 3;
                Console. log ("the rotation mode of the current character camera"+CameraRotationMode [myCamera. motionMode]);
            });
        }
    }
}

Returns

CameraRotationMode

Rotate mode

Precautions

Camera rotation mode. Fixed orientation: The camera is fixed in a certain direction. Follow direction: The camera follows the direction of the target face. Control orientation: the orientation of the camera is controlled by the input control.

Parameters

value CameraRotationModeRotate mode

upAngleLimit

get upAngleLimit(): number other

set upAngleLimit(value): void other

Upward angle limitation

Precautions

The maximum angle range for the camera to rotate upwards is between 0-90.

Usage example: create a script named "Example_Camera_UpAngleLimit", place it in the object bar, open the script, enter the following code to save, run the game, set the camera angle limit, and set the maximum upward angle to 30, and the maximum downward rotation angle to 10. You will see the effect of limited camera rotation in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_UpAngleLimit extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}
@Component
export default class Example_Camera_UpAngleLimit extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get Player character
            let myCharacter = myPlayer.character;
            // Get the current camera
            let myCamera = Camera.currentCamera;
            // Enable camera position delay
            myCamera.positionLagEnabled = true;
            // Position delay redo speed 1
            myCamera.positionLagSpeed = 1;
            // Maximum position delay distance of 200
            myCamera.maxLagDistance = 200;
            // Turn on camera rotation delay
            myCamera.rotationLagEnabled = true;
            // Rotation delay recovery speed 2
            myCamera.rotationLagSpeed = 2;
            // Set camera angle limit
            myCamera.upAngleLimit = 30
            myCamera.downAngleLimit = 10;
            // Add a key method: press the keyboard "1", fix the height of the camera and jump
            InputUtil.onKeyDown(Keys.One, () => {
                myCamera.fixedElevation = true;
                myCharacter.jump();
                setTimeout(() => {
                    myCamera.fixedElevation = false;
                }, 1000);
            });
            // Add a button method: Press and hold the keyboard "2" to increase the camera FOV
            InputUtil.onKeyPress(Keys.Two, () => {
                myCamera.fov += 1;
            });
            // Add a button method: Hold down keyboard "3" to reduce camera FOV
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.fov -= 1;
            });
        }
    }
}

Returns

number

Upward angle limitation

Precautions

When the camera rotates upward, the maximum angle range is 0-91.

Parameters

value numberAngle limitation

currentCamera

Static get currentCamera(): Camera other

Current camera

Precautions

Camera currently in use

Example usage: Create a script called "CurrentCamera", place it in the object bar, open the script, enter the following code to save, run the game, and randomly create 5 cameras in the scene. Press "1" on the keyboard to switch the camera. Press keyboard "2" to switch back to the default camera. You will see the effect of camera switching in the scene. The code is as follows:

ts
@Component
export default class CurrentCamera extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current camera
            let myCamera = Camera.currentCamera;
            let curCameraIndex = -1;
            // Create 5 camera randomly in the scene
            let cameraArray = new Array<Camera>();
            for (let i = 0;
i < 5;
i++) {
                let camera = GameObject.spawn<Camera>("Camera") as Camera;
                camera.worldTransform.position = new Vector(MathUtil.randomInt(-1000, 1000), MathUtil.randomInt(-1000, 1000),MathUtil.randomInt(0, 1000));
                camera.worldTransform.rotation = new Rotation(MathUtil.randomInt(-90, 90), MathUtil.randomInt(-30, 30),MathUtil.randomInt(-150, 150));
                cameraArray.push(camera);
                camera.onSwitchComplete.add(() => {
                    Console.log ("current camera serial number"+i);
                    curCameraIndex = i;
                });
            }
            // Add a key method: press the keyboard "1" to switch the camera
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Switch Camera");
                let newCamera = (curCameraIndex + 1) % 5;
                Camera.switch(cameraArray[newCamera], 5, CameraSwitchBlendFunction.Linear);
            });
            // Add a key method: press "2" on the keyboard to switch back to the default camera
            InputUtil.onKeyDown(Keys.Two, () => {
                console.log("Switch Default Camera");
                Camera.switch(myCamera);
            });
        }
    }
}
@Component
export default class CurrentCamera extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current camera
            let myCamera = Camera.currentCamera;
            let curCameraIndex = -1;
            // Create 5 camera randomly in the scene
            let cameraArray = new Array<Camera>();
            for (let i = 0;
i < 5;
i++) {
                let camera = GameObject.spawn<Camera>("Camera") as Camera;
                camera.worldTransform.position = new Vector(MathUtil.randomInt(-1000, 1000), MathUtil.randomInt(-1000, 1000),MathUtil.randomInt(0, 1000));
                camera.worldTransform.rotation = new Rotation(MathUtil.randomInt(-90, 90), MathUtil.randomInt(-30, 30),MathUtil.randomInt(-150, 150));
                cameraArray.push(camera);
                camera.onSwitchComplete.add(() => {
                    Console.log ("current camera serial number"+i);
                    curCameraIndex = i;
                });
            }
            // Add a key method: press the keyboard "1" to switch the camera
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Switch Camera");
                let newCamera = (curCameraIndex + 1) % 5;
                Camera.switch(cameraArray[newCamera], 5, CameraSwitchBlendFunction.Linear);
            });
            // Add a key method: press "2" on the keyboard to switch back to the default camera
            InputUtil.onKeyDown(Keys.Two, () => {
                console.log("Switch Default Camera");
                Camera.switch(myCamera);
            });
        }
    }
}

Returns

Camera

Methods


lock

lock(target, val?): void other

Camera locks target

Parameters

target GameObjectUsage: target object
val? ObjectUsage: lockInterval, lockSpeed, lockRange, lockDistance, lockOffset, bPause parameter set default: null
val.bPause? boolean-
val.lockDistance? number-
val.lockInterval? number-
val.lockOffset? Vector-
val.lockRange? number-
val.lockRotationY? boolean-
val.lockRotationZ? boolean-
val.lockSpeed? number-

Precautions

The current camera locks the target object according to the parameter settings.

Example usage: Create a script called "Instance_Camera_Lock", place it in the object bar, open the script, enter the following code to save, run the game, and create an enemy character as the lock target. Enemy characters will continue to track player characters. Press keyboard "1" to lock the enemy character. Press keyboard "2" to manually unlock: When the bPause parameter is true, manual unlocking is required to end the locking process. Press keyboard "3" and the character camera will face the target (no tracking effect). You will see the effect of locking the toggle in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_Lock extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get the current player character
            let myCharacter = myPlayer.character;
            // Create an enemy character as a locked target
            let enemy = Player.spawnDefaultCharacter();
            enemy.switchToFlying()
            enemy.worldTransform.position = new Vector(1000, 500, 130);
            // Enemy character tracking player character
            TimeUtil.setInterval(() => {
                let distance = Vector.subtract(myCharacter.worldTransform.position, enemy.worldTransform.position);
                if(distance.length < 200) {
                    enemy.addMovement(new Vector(0, 0, 5));
                } else {
                    let dir = distance.normalized;
                    enemy.addMovement(dir);
                    enemy.worldTransform.rotation = distance.toRotation();
                }
            }, 0.02)
            // Add a key method: press the keyboard "1" to lock the enemy character
            InputUtil.onKeyDown(Keys.One, () => {
                console.error("Start Lock");
                let myCamera = Camera.currentCamera;
                myCamera.lock(enemy, {lockInterval:0, lockSpeed: 0, lockRange: 500, lockDistance: 5000, lockOffset: new Vector(0, 0, 80), bPause: true});
            });
            // Add a key method: press the keyboard "2", manually unlock: when the bPause parameter is true, manually unlock is required to end the locking process
            InputUtil.onKeyDown(Keys.Two, () => {
                let myCamera = Camera.currentCamera;
                myCamera.unlock();
            });
            // Add a key method: Press keyboard "3" and the character looks towards the target (no tracking effect)
            InputUtil.onKeyDown(Keys.Three, () => {
                let myCamera = Camera.currentCamera;
                myCamera.lookAt(enemy);
            });
        }
    }
}
@Component
export default class Example_Camera_Lock extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get the current player character
            let myCharacter = myPlayer.character;
            // Create an enemy character as a locked target
            let enemy = Player.spawnDefaultCharacter();
            enemy.switchToFlying()
            enemy.worldTransform.position = new Vector(1000, 500, 130);
            // Enemy character tracking player character
            TimeUtil.setInterval(() => {
                let distance = Vector.subtract(myCharacter.worldTransform.position, enemy.worldTransform.position);
                if(distance.length < 200) {
                    enemy.addMovement(new Vector(0, 0, 5));
                } else {
                    let dir = distance.normalized;
                    enemy.addMovement(dir);
                    enemy.worldTransform.rotation = distance.toRotation();
                }
            }, 0.02)
            // Add a key method: press the keyboard "1" to lock the enemy character
            InputUtil.onKeyDown(Keys.One, () => {
                console.error("Start Lock");
                let myCamera = Camera.currentCamera;
                myCamera.lock(enemy, {lockInterval:0, lockSpeed: 0, lockRange: 500, lockDistance: 5000, lockOffset: new Vector(0, 0, 80), bPause: true});
            });
            // Add a key method: press the keyboard "2", manually unlock: when the bPause parameter is true, manually unlock is required to end the locking process
            InputUtil.onKeyDown(Keys.Two, () => {
                let myCamera = Camera.currentCamera;
                myCamera.unlock();
            });
            // Add a key method: Press keyboard "3" and the character looks towards the target (no tracking effect)
            InputUtil.onKeyDown(Keys.Three, () => {
                let myCamera = Camera.currentCamera;
                myCamera.lookAt(enemy);
            });
        }
    }
}

lookAt

lookAt(target): void other

Camera towards target

Parameters

target GameObject VectorUsage: target

Usage example: create a script named "Example_Camera_LookAt", place it in the object bar, open the script, enter the following code to save, run the game, and create an enemy character as a locked target. Enemy character will continue to track Player character. Press "1" on the keyboard to lock the enemy character. Press "2" on the keyboard to manually unlock: when the bPause parameter is true, manually unlocking is required to end the locking process. Press "3" on the keyboard, and the character camera faces the target (no tracking effect). You will see the effect of lock switching in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_LookAt extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get the current player character
            let myCharacter = myPlayer.character;
            // Create an enemy character as a locked target
            let enemy = Player.spawnDefaultCharacter();
            enemy.switchToFlying()
            enemy.worldTransform.position = new Vector(1000, 500, 130);
            // Enemy character tracking player character
            TimeUtil.setInterval(() => {
                let distance = Vector.subtract(myCharacter.worldTransform.position, enemy.worldTransform.position);
                if(distance.length < 200) {
                    enemy.addMovement(new Vector(0, 0, 5));
                } else {
                    let dir = distance.normalized;
                    enemy.addMovement(dir);
                    enemy.worldTransform.rotation = distance.toRotation();
                }
            }, 0.02)
            // Add a key method: press the keyboard "1" to lock the enemy character
            InputUtil.onKeyDown(Keys.One, () => {
                console.error("Start Lock");
                let myCamera = Camera.currentCamera;
                myCamera.lock(enemy, {lockInterval:0, lockSpeed: 0, lockRange: 500, lockDistance: 5000, lockOffset: new Vector(0, 0, 80), bPause: true});
            });
            // Add a key method: press the keyboard "2", manually unlock: when the bPause parameter is true, manually unlock is required to end the locking process
            InputUtil.onKeyDown(Keys.Two, () => {
                let myCamera = Camera.currentCamera;
                myCamera.unlock();
            });
            // Add a key method: Press keyboard "3" and the character looks towards the target (no tracking effect)
            InputUtil.onKeyDown(Keys.Three, () => {
                let myCamera = Camera.currentCamera;
                myCamera.lookAt(enemy);
            });
        }
    }
}
@Component
export default class Example_Camera_LookAt extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get the current player character
            let myCharacter = myPlayer.character;
            // Create an enemy character as a locked target
            let enemy = Player.spawnDefaultCharacter();
            enemy.switchToFlying()
            enemy.worldTransform.position = new Vector(1000, 500, 130);
            // Enemy character tracking player character
            TimeUtil.setInterval(() => {
                let distance = Vector.subtract(myCharacter.worldTransform.position, enemy.worldTransform.position);
                if(distance.length < 200) {
                    enemy.addMovement(new Vector(0, 0, 5));
                } else {
                    let dir = distance.normalized;
                    enemy.addMovement(dir);
                    enemy.worldTransform.rotation = distance.toRotation();
                }
            }, 0.02)
            // Add a key method: press the keyboard "1" to lock the enemy character
            InputUtil.onKeyDown(Keys.One, () => {
                console.error("Start Lock");
                let myCamera = Camera.currentCamera;
                myCamera.lock(enemy, {lockInterval:0, lockSpeed: 0, lockRange: 500, lockDistance: 5000, lockOffset: new Vector(0, 0, 80), bPause: true});
            });
            // Add a key method: press the keyboard "2", manually unlock: when the bPause parameter is true, manually unlock is required to end the locking process
            InputUtil.onKeyDown(Keys.Two, () => {
                let myCamera = Camera.currentCamera;
                myCamera.unlock();
            });
            // Add a key method: Press keyboard "3" and the character looks towards the target (no tracking effect)
            InputUtil.onKeyDown(Keys.Three, () => {
                let myCamera = Camera.currentCamera;
                myCamera.lookAt(enemy);
            });
        }
    }
}

unlock

unlock(): void other

Unlock target

Usage example: create a script named "Example_Camera_Unlock", place it in the object bar, open the script, enter the following code to save it, run the game, and create an enemy character as the locking target. Enemy characters will continue to track player characters. Press "1" on the keyboard to lock the enemy character. Press keyboard "2" to manually unlock: When the bPause parameter is true, manual unlocking is required to end the locking process. Press keyboard "3" and the character camera will face the target (no tracking effect). You will see the effect of locking the toggle in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_Unlock extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get the current player character
            let myCharacter = myPlayer.character;
            // Create an enemy character as a locked target
            let enemy = Player.spawnDefaultCharacter();
            enemy.switchToFlying()
            enemy.worldTransform.position = new Vector(1000, 500, 130);
            // Enemy character tracking player character
            TimeUtil.setInterval(() => {
                let distance = Vector.subtract(myCharacter.worldTransform.position, enemy.worldTransform.position);
                if(distance.length < 200) {
                    enemy.addMovement(new Vector(0, 0, 5));
                } else {
                    let dir = distance.normalized;
                    enemy.addMovement(dir);
                    enemy.worldTransform.rotation = distance.toRotation();
                }
            }, 0.02)
            // Add a key method: press the keyboard "1" to lock the enemy character
            InputUtil.onKeyDown(Keys.One, () => {
                console.error("Start Lock");
                let myCamera = Camera.currentCamera;
                myCamera.lock(enemy, {lockInterval:0, lockSpeed: 0, lockRange: 500, lockDistance: 5000, lockOffset: new Vector(0, 0, 80), bPause: true});
            });
            // Add a key method: press the keyboard "2", manually unlock: when the bPause parameter is true, manually unlock is required to end the locking process
            InputUtil.onKeyDown(Keys.Two, () => {
                let myCamera = Camera.currentCamera;
                myCamera.unlock();
            });
            // Add a key method: Press keyboard "3" and the character looks towards the target (no tracking effect)
            InputUtil.onKeyDown(Keys.Three, () => {
                let myCamera = Camera.currentCamera;
                myCamera.lookAt(enemy);
            });
        }
    }
}
@Component
export default class Example_Camera_Unlock extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current client's Player (himself)
            let myPlayer = Player.localPlayer;
            // Get the current player character
            let myCharacter = myPlayer.character;
            // Create an enemy character as a locked target
            let enemy = Player.spawnDefaultCharacter();
            enemy.switchToFlying()
            enemy.worldTransform.position = new Vector(1000, 500, 130);
            // Enemy character tracking player character
            TimeUtil.setInterval(() => {
                let distance = Vector.subtract(myCharacter.worldTransform.position, enemy.worldTransform.position);
                if(distance.length < 200) {
                    enemy.addMovement(new Vector(0, 0, 5));
                } else {
                    let dir = distance.normalized;
                    enemy.addMovement(dir);
                    enemy.worldTransform.rotation = distance.toRotation();
                }
            }, 0.02)
            // Add a key method: press the keyboard "1" to lock the enemy character
            InputUtil.onKeyDown(Keys.One, () => {
                console.error("Start Lock");
                let myCamera = Camera.currentCamera;
                myCamera.lock(enemy, {lockInterval:0, lockSpeed: 0, lockRange: 500, lockDistance: 5000, lockOffset: new Vector(0, 0, 80), bPause: true});
            });
            // Add a key method: press the keyboard "2", manually unlock: when the bPause parameter is true, manually unlock is required to end the locking process
            InputUtil.onKeyDown(Keys.Two, () => {
                let myCamera = Camera.currentCamera;
                myCamera.unlock();
            });
            // Add a key method: Press keyboard "3" and the character looks towards the target (no tracking effect)
            InputUtil.onKeyDown(Keys.Three, () => {
                let myCamera = Camera.currentCamera;
                myCamera.lookAt(enemy);
            });
        }
    }
}

shake

Static shake(shakeInfo, duration?): void other

Start camera shake

Parameters

shakeInfo CameraShakeInfoShake information
duration? numberDuration (seconds) default: 1 range: unlimited type: floating point

Example usage: Create a script called "Instance_Camera_Shake", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", shake the camera for 5 seconds. Press keyboard "2" to stop camera shake. You will see the effect of shake of the camera lens in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_Shake extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Add a key method: press the keyboard "1", shake the camera for 5 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Start Shake ");
                Camera.shake({positionYAmplitude: 1, positionYFrequency: 0.5, positionZAmplitude: 1, positionZFrequency: 1}, 5);
            });
            // Add a key method: press "2" on the keyboard to stop camera shake
            InputUtil.onKeyUp(Keys.Two, () => {
                console.log("Stop Shake ");
                Camera.stopShake();
            });
        }
    }
}
@Component
export default class Example_Camera_Shake extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Add a key method: press the keyboard "1", shake the camera for 5 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Start Shake ");
                Camera.shake({positionYAmplitude: 1, positionYFrequency: 0.5, positionZAmplitude: 1, positionZFrequency: 1}, 5);
            });
            // Add a key method: press "2" on the keyboard to stop camera shake
            InputUtil.onKeyUp(Keys.Two, () => {
                console.log("Stop Shake ");
                Camera.stopShake();
            });
        }
    }
}

stopShake

Static stopShake(): void other

Stop camera shake

Example usage: Create a script called "Instance_Camera_StopShake", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", shake the camera for 5 seconds. Press keyboard "2" to stop camera shake. You will see the effect of camera shake in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_StopShake extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Add a key method: press the keyboard "1", shake the camera for 5 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Start Shake ");
                Camera.shake({positionYAmplitude: 1, positionYFrequency: 0.5, positionZAmplitude: 1, positionZFrequency: 1}, 5);
            });
            // Add a key method: press "2" on the keyboard to stop camera shake
            InputUtil.onKeyUp(Keys.Two, () => {
                console.log("Stop Shake ");
                Camera.stopShake();
            });
        }
    }
}
@Component
export default class Example_Camera_StopShake extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Add a key method: press the keyboard "1", shake the camera for 5 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Start Shake ");
                Camera.shake({positionYAmplitude: 1, positionYFrequency: 0.5, positionZAmplitude: 1, positionZFrequency: 1}, 5);
            });
            // Add a key method: press "2" on the keyboard to stop camera shake
            InputUtil.onKeyUp(Keys.Two, () => {
                console.log("Stop Shake ");
                Camera.stopShake();
            });
        }
    }
}

switch

Static switch(newCamera, blendTime?, blendFunc?, blendExp?): Camera other

Switch camera

Parameters

newCamera CameraThe target camera object you want to switch will use the position of the Transform and rotate generate a Camera when the incoming parameter type is Transform.
blendTime? numberMixing time (seconds) default: 0 range: no limit type: floating point number
blendFunc? CameraSwitchBlendFunctionMixing function used during switching default: Linear
blendExp? numberMixing additional variables, used to control the speed of mixing, the specific function depends on the enumeration SwitchCameraBlend Function default: 0 range: no restriction type: floating point number

Returns

CameraTarget camera object

Usage example: create a script named "Example_Camera_Switch", place it in the object bar, open the script, enter the following code to save, run the game, and randomly create 5 camera in the scene. Press "1" on the keyboard to switch the camera. Press "2" on the keyboard to switch back to the default camera. You will see the effect of camera switching in the scene. The code is as follows:

ts
@Component
export default class Example_Camera_Switch extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current camera
            let myCamera = Camera.currentCamera;
            let curCameraIndex = -1;
            // Create 5 camera randomly in the scene
            let cameraArray = new Array<Camera>();
            for (let i = 0;
i < 5;
i++) {
                let camera = GameObject.spawn<Camera>("Camera") as Camera;
                camera.worldTransform.position = new Vector(MathUtil.randomInt(-1000, 1000), MathUtil.randomInt(-1000, 1000),MathUtil.randomInt(0, 1000));
                camera.worldTransform.rotation = new Rotation(MathUtil.randomInt(-90, 90), MathUtil.randomInt(-30, 30),MathUtil.randomInt(-150, 150));
                cameraArray.push(camera);
                camera.onSwitchComplete.add(() => {
                    Console.log ("current camera serial number"+i);
                    curCameraIndex = i;
                });
            }
            // Add a key method: press the keyboard "1" to switch the camera
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Switch Camera");
                let newCamera = (curCameraIndex + 1) % 5;
                Camera.switch(cameraArray[newCamera], 5, CameraSwitchBlendFunction.Linear);
            });
            // Add a key method: press "2" on the keyboard to switch back to the default camera
            InputUtil.onKeyDown(Keys.Two, () => {
                console.log("Switch Default Camera");
                Camera.switch(myCamera);
            });
        }
    }
}
@Component
export default class Example_Camera_Switch extends Script {
    // When the script is instantiated, this function will be called before the first frame update
    protected onStart(): void {
        // The following code is only executed on the client side
        if(SystemUtil.isClient()) {
            // Get the current camera
            let myCamera = Camera.currentCamera;
            let curCameraIndex = -1;
            // Create 5 camera randomly in the scene
            let cameraArray = new Array<Camera>();
            for (let i = 0;
i < 5;
i++) {
                let camera = GameObject.spawn<Camera>("Camera") as Camera;
                camera.worldTransform.position = new Vector(MathUtil.randomInt(-1000, 1000), MathUtil.randomInt(-1000, 1000),MathUtil.randomInt(0, 1000));
                camera.worldTransform.rotation = new Rotation(MathUtil.randomInt(-90, 90), MathUtil.randomInt(-30, 30),MathUtil.randomInt(-150, 150));
                cameraArray.push(camera);
                camera.onSwitchComplete.add(() => {
                    Console.log ("current camera serial number"+i);
                    curCameraIndex = i;
                });
            }
            // Add a key method: press the keyboard "1" to switch the camera
            InputUtil.onKeyDown(Keys.One, () => {
                console.log("Switch Camera");
                let newCamera = (curCameraIndex + 1) % 5;
                Camera.switch(cameraArray[newCamera], 5, CameraSwitchBlendFunction.Linear);
            });
            // Add a key method: press "2" on the keyboard to switch back to the default camera
            InputUtil.onKeyDown(Keys.Two, () => {
                console.log("Switch Default Camera");
                Camera.switch(myCamera);
            });
        }
    }
}