Skip to content
HotWeaponAimComponent

Gameplay / HotWeaponAimComponent

HotWeaponAimComponent Class

The hot weapon aiming component will bring the perspective of the gun wielding character closer in the aiming state

Usage example: create a script named "HotWeaponAimSample1", place it in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:

ts
@Component
export default class HotWeaponAimSample1 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.aimEnabled = true;
            hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
            hotWeapon.aimComponent.aimingZoom = 16;
            hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;
            hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
            hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
            hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
        }
    }
}
@Component
export default class HotWeaponAimSample1 extends Script {
    protected onStart(): void {
        // structure
        const hotWeapon = this.gameObject as HotWeapon;

        if (SystemUtil.isServer()) {
            hotWeapon.aimEnabled = true;
            hotWeapon.aimComponent.aimMode = HotWeaponAimMode.ThirdPerson;
            hotWeapon.aimComponent.aimingZoom = 16;
            hotWeapon.aimComponent.cameraOffsetDistanceInThirdPersonMode = 300;
            hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
            hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
        } else if (SystemUtil.isClient()) {
            hotWeapon.aimComponent.onStartAim.add(() => { console.log("aimComponent.onAimStartClient") });
            hotWeapon.aimComponent.onEndAim.add(() => { console.log("aimComponent.onAimEndClient") });
        }
    }
}

Table of contents

Properties

onEndAim: MulticastDelegateInterface<() => void>
The server-side is starting to target the agents. Example usage: See class HotWeaponAimComponent usage example
onStartAim: MulticastDelegateInterface<() => void>
Server side starts aim agent

Accessors

aimMode(): HotWeaponAimMode other
Get the first/third person mode when aim.
aimingZoom(): number other
Get the magnification of scope when first person aim.
cameraOffsetDistanceInThirdPersonMode(): number other
Get the length of the component connecting the camera spring when the third person is aim.
defaultCameraSpringArmLength(): number other
Get the default length of the camera spring component in the third person normal state.

Methods

enableAiming(enabled: boolean): void other
Turn on/off aiming

Properties

onEndAim

onEndAim: MulticastDelegateInterface<() => void>

The server-side is starting to target the agents. Example usage: See class HotWeaponAimComponent usage example


onStartAim

onStartAim: MulticastDelegateInterface<() => void>

Server side starts aim agent

Accessors

aimMode

get aimMode(): HotWeaponAimMode other

set aimMode(NewAimMode): void other

Get the first/third person mode when aim.

Returns

HotWeaponAimModeThe first/third person mode in the current aim

Set the first/third person mode when aim.

Parameters

NewAimMode HotWeaponAimModeNew aim mode
default: third person HotWeaponAimMode ThirdPerson

aimingZoom

get aimingZoom(): number other

set aimingZoom(newAimingZoom): void other

Get the magnification of scope when first person aim.

Precautions

The legal range is [1.0, 18.0], and for every 1.0 increase in FOV value corresponding to [0 °, 90 °], the corresponding FOV increases by 5 °

Returns

numberMagnification of the scope during current first person aiming

Set the magnification of the sight when simulating aiming. For the usage example, see the usage example of the HotWeaponAimComponent class

Precautions

The legal range is [1.0, 18.0], and for every 1.0 increase in FOV value corresponding to [0 °, 90 °], the corresponding FOV increases by 5 °

Parameters

newAimingZoom numberNewly set scope magnification
default: 1
range: [0, 16] type: floating point

cameraOffsetDistanceInThirdPersonMode

get cameraOffsetDistanceInThirdPersonMode(): number other

set cameraOffsetDistanceInThirdPersonMode(NewCameraOffsetDistance): void other

Get the length of the component connecting the camera spring when the third person is aim.

Returns

numberLength of currently connected camera spring component

Set the length of the component connecting the camera spring when the third person is aim.

Precautions

The length of the camera spring component has a closed range to prevent the camera from getting too close to the Character and causing it to pass through the mold. If it is too far away, it is not necessary

Parameters

NewCameraOffsetDistance numberThe newly set length of the connecting camera spring component
default: 400
range: [300, 600] type: floating point number

defaultCameraSpringArmLength

get defaultCameraSpringArmLength(): number other

set defaultCameraSpringArmLength(NewCameraArmLength): void other

Get the default length of the camera spring component in the third person normal state.

Returns

numberDefault length of camera spring component in the third person normal state

Set the default length of the camera spring component in third person normal.

Precautions

The length of the camera spring component has a closed range to prevent the camera from getting too close to the Character and causing it to pass through the mold. If it is too far away, it is not necessary

Parameters

NewCameraArmLength numberThe newly set default length of the connected camera spring component
default: 400
range: [300, 600] type: floating point number

Methods

enableAiming

enableAiming(enabled): void other

Turn on/off aiming

Parameters

enabled booleanWhether to enable the aiming function default:
  • Switch camera view
  • Switch the crosshair UI
  • Modify bullet firing accuracy - Ascend to user level, developers can set default accuracy when aiming themselves