Skip to content
SpringArm

Gameplay / SpringArm

SpringArm Class

Spring arm

Table of contents

Accessors

collisionEnabled(): boolean other
Enable collision
collisionInterpSpeed(): number other
Collision interpolation speed, this value is used to adjust the speed at which the camera returns from a collision state to a non collision state, making the camera collision effect smoother
length(): number other
Length of spring arm
localTransform(): Transform other
Relative transformation of spring arm
useControllerRotation(): boolean other
Use the controller to control rotation
worldTransform(): Transform other
World transformation of spring arm
zoomDistanceRange(): Vector2 other
Camera zoom range
zoomEnabled(): boolean other
Do you want to enable the camera to zoom in and out
zoomScale(): number other
Camera zoom distance input ratio

Accessors

collisionEnabled

get collisionEnabled(): boolean other

set collisionEnabled(value): void other

Enable collision

Precautions

After opening, the spring arm will detect the collision object and retract to the collision object nearest to the target Note: To modify the detection trajectory, it is necessary to modify the length of the spring arm (Targeted Arm Length) as well as the targetOffset and slotOffset. Directly modifying the position of the spring arm may result in the offset not triggering collision contraction

Usage example: drag the used asset: "26950" into the priority loading column. Create a script called 'Instance_SpringArm', place it in the object bar, open the script, enter the following code to save, run the game, and you will generate 10 pillars in the scene to trigger camera spring rod collision. Press the keyboard '1' to enable/disable camera spring rod collision. You can see the different effects of disabling the camera spring rod collision camera collision pillar. The code is as follows:

ts
@Component
export default class Example_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 Example_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);
            });
        }
    }
}

Returns

boolean

Enable collision

Precautions

After opening, the spring arm will detect the collision object and retract to the collision object nearest to the target Note: To modify the detection trajectory, it is necessary to modify the length of the spring arm (Targeted Arm Length) as well as the targetOffset and slotOffset. Directly modifying the position of the spring arm may result in the offset not triggering collision contraction

Parameters

value booleanIs it enabled

collisionInterpSpeed

get collisionInterpSpeed(): number other

set collisionInterpSpeed(value): void other

Collision interpolation speed, this value is used to adjust the speed at which the camera returns from a collision state to a non collision state, making the camera collision effect smoother

Precautions

The default value is 2, with an effective range of 0-20. The higher the value, the faster the speed. When it is equal to 0, the camera collision interpolation effect will be turned off; The speed is not fixed, but will change from fast to slow

Usage example: drag the used asset: "26950" into the priority loading column. Create a script called 'Instance_SpringArm', place it in the object bar, open the script, enter the following code to save, run the game, and you will generate 10 pillars in the scene to trigger camera spring rod collision. Press the keyboard '1' to enable/disable camera spring rod collision. You can see the different effects of disabling the camera spring rod collision camera collision pillar. The code is as follows:

ts
@Component
export default class Example_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 Example_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);
            });
        }
    }
}

Returns

number

Collision interpolation speed, this value is used to adjust the speed at which the camera returns from a collision state to a non collision state, making the camera collision effect smoother

Precautions

The default value is 2, with an effective range of 0-20. The higher the value, the faster the speed. When it is equal to 0, the camera collision interpolation effect will be turned off; The speed is not fixed, but will change from fast to slow

Parameters

value numberIs it enabled

length

get length(): number other

set length(value): void other

Length of spring arm

Precautions

Adjust the distance between the camera and the hanging point

Usage example: create a script named "Example_SpringArm_Length", place it in the object bar, open the script, enter the following code to save, run the game, press and hold the keyboard "3" to increase the length of the camera spring arm, and press and hold the keyboard "4" to reduce the length of the camera spring arm. In the scene, you will see the spring rod of the camera telescoping. The code is as follows:

ts
@Component
export default class Example_SpringArm_Length 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}
@Component
export default class Example_SpringArm_Length 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}

Returns

number

Length of spring arm

Precautions

Adjust the distance between the camera and the hanging point

Parameters

value numberLength of spring arm

localTransform

get localTransform(): Transform other

set localTransform(value): void other

Relative transformation of spring arm

Usage example: create a script named "Example_SpringArm_LocalTransform", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", switch the offset of the spring arm of the camera (0, 100, 100), and restore it 2 seconds later. You will see the effect of camera offset in the scene and the local transformation of camera spring arm after the change of printing on the console. The code is as follows:

ts
@Component
export default class Example_SpringArm_LocalTransform 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}
@Component
export default class Example_SpringArm_LocalTransform 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}

Returns

Transform

Relative transformation of spring arm

Precautions

Relative transformation of spring arm, used to set the relative position, relative rotation and relative scale of spring arm

Parameters

value TransformTransformation

useControllerRotation

get useControllerRotation(): boolean other

set useControllerRotation(value): void other

Use the controller to control rotation

Precautions

After turning on, use the rotation of the controller as the rotation of the camera

Example usage: Create a script called "Instance_SpringArm_SseControlRotation", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "2", enable/disable the controller to rotate the camera for 5 seconds. You will see in the scene that after disable the controller to operate the camera, you cannot control the camera rotation. The code is as follows:

ts
@Component
export default class Example_SpringArm_UseControllerRotation 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}
@Component
export default class Example_SpringArm_UseControllerRotation 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}

Returns

boolean

Use the controller to control rotation

Precautions

After turning on, use the rotation of the controller as the rotation of the camera

Parameters

value booleanWhether to use the controller to control rotation

worldTransform

get worldTransform(): Transform other

set worldTransform(value): void other

World transformation of spring arm

Precautions

World transformation of spring arm, used to set world position, world rotation and world scale of spring arm

Usage example: create a script named "Example_SpringArm_WorldTransform", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "1", switch the offset of the spring arm of the camera (0, 100, 100), and restore it 2 seconds later. You will see the effect of camera offset in the scene and the world transformation of camera spring arm after the change of printing on the console. The code is as follows:

ts
@Component
export default class Example_SpringArm_WorldTransform 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}
@Component
export default class Example_SpringArm_WorldTransform 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}

Returns

Transform

World transformation of spring arm

Precautions

World transformation of spring arm, used to set world position, world rotation and world scale of spring arm

Parameters

value TransformTransformation

zoomDistanceRange

get zoomDistanceRange(): Vector2 other

set zoomDistanceRange(value): void other

Camera zoom range

Precautions

Double finger or mouse scroll zoom camera spring arm length range, default value 60~500

Usage example: create a script named "Example_SpringArm_UseControllerRotation", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "2", enable/disable the controller to operate the rotation of the camera for 5 seconds. You will see in the scene the effect that the controller cannot control the rotation of the camera after disable the controller to operate the camera. The code is as follows:

ts
@Component
export default class Example_SpringArm_UseControllerRotation 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}
@Component
export default class Example_SpringArm_UseControllerRotation 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}

Returns

Vector2

Camera zoom range

Precautions

Double finger or mouse scroll zoom camera spring arm length range, default value 60~500

Parameters

valueVector2

zoomEnabled

get zoomEnabled(): boolean other

set zoomEnabled(value): void other

Do you want to enable the camera to zoom in and out

Precautions

Whether to enable double fingers or mouse wheel to zoom in/out the length of camera spring arm, which is enabled by default, only takes effect when the current camera spring arm length is within the zoom in/out distance of camera

Example usage: Create a script called "Instance_SpringArm_SseControlRotation", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "2", enable/disable the controller to rotate the camera for 5 seconds. You will see in the scene that after disable the controller to operate the camera, you cannot control the camera rotation. The code is as follows:

ts
@Component
export default class Example_SpringArm_UseControllerRotation 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}
@Component
export default class Example_SpringArm_UseControllerRotation 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}

Returns

boolean

Do you want to enable the camera to zoom in and out

Precautions

Whether to enable double fingers or mouse wheel to zoom in/out the length of camera spring arm, which is enabled by default, only takes effect when the current camera spring arm length is within the zoom in/out distance of camera

Parameters

valueboolean

zoomScale

get zoomScale(): number other

set zoomScale(value): void other

Camera zoom distance input ratio

Precautions

When controlling the distance between two fingers or scrolling the mouse wheel to change the unit distance, the length of the camera spring arm changes by a default value of 1, with a range of 0-10

Example usage: Create a script called "Instance_SpringArm_SseControlRotation", place it in the object bar, open the script, enter the following code to save, run the game, press the keyboard "2", enable/disable the controller to rotate the camera for 5 seconds. You will see in the scene that after disable the controller to operate the camera, you cannot control the camera rotation. The code is as follows:

ts
@Component
export default class Example_SpringArm_UseControllerRotation 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}
@Component
export default class Example_SpringArm_UseControllerRotation 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;
            // Add a key method: press the keyboard "1" to switch the offset of the camera spring arm (0, 100, 100), and restore it after 2 seconds
            InputUtil.onKeyDown(Keys.One, () => {
                Console.log ("local transformation of camera spring arm"+myCamera. springArm. localTransform);
                Console. log ("world transformation of camera spring arm"+myCamera. springArm. worldTransform);
            });
            // Add a button method: Press keyboard "2" to enable/disable the controller to rotate the camera for 5 seconds
            InputUtil.onKeyDown(Keys.Two, () => {
                myCamera.springArm.useControllerRotation = false;
                setTimeout(() => {
                    myCamera.springArm.useControllerRotation = true;
                }, 5000);
            });
            // Add a key method: press and hold the keyboard "3" to increase the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Three, () => {
                myCamera.springArm.length += 1;
            });
            // Add a key method: press and hold the keyboard "4" to reduce the length of the spring arm of the camera
            InputUtil.onKeyPress(Keys.Four, () => {
                myCamera.springArm.length -= 1;
            });
        }
    }
}

Returns

number

Camera zoom distance input ratio

Precautions

When controlling the distance between two fingers or scrolling the mouse wheel to change the unit distance, the length of the camera spring arm changes by a default value of 1, with a range of 0-10

Parameters

valuenumber