Gameplay / HotWeaponAccuracyOfFireComponent
HotWeaponAccuracyOfFireComponent Class
Hot Weapon shoot precision component
Weapon shooting accuracy refers to the accuracy and precision of the weapon hitting the target during shooting. It describes the stability and predictability of the ballistic path when the weapon is in use, as well as the hit rate and accuracy of shoot. Control the divergence of bullets when Hot Weapon is launched. It is the minimum divergence by default
The shoot accuracy of weapons can be described by a simple analogy: it is like the shooting accuracy when you play basketball.
When you shoot, you want the basketball to enter the basket accurately, rather than deviate from the target. This is the accuracy of shooting. In weapon shooting, accuracy refers to the ability of the bullets fired by the weapon to accurately hit the target, rather than flying randomly in other directions.
Usage example: create a script named "HotWeaponAofSample1", place it in the object manager, open the script, enter the following code to save, and run the game. The code is as follows:
@Component
export default class HotWeaponAofSample1 extends Script {
protected onStart(): void {
// structure
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.accuracyOfFireEnable = true;
// The maximum value of bullet offset half angle that affects shooting accuracy (range Min~88)
hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
// The minimum value of offset half angle of bullet that affects shoot accuracy (range 0~Max)
hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
// Default offset half angle of bullet that affects shoot accuracy (range Min~Max)
hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
// The expansion speed per second of the bullet offset half angle that affects shooting accuracy (range 0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
// The contraction speed per second (range 0~88) of bullet offset half angle that affects shooting accuracy
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
// Each firing expansion value of offset half angle of bullet that affects shoot accuracy (range 0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;
} else if (SystemUtil.isClient()) {
hotWeapon.accuracyOfFireComponent.onCurrentDispersionChangedClient.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });
}
}
}
@Component
export default class HotWeaponAofSample1 extends Script {
protected onStart(): void {
// structure
const hotWeapon = this.gameObject as HotWeapon;
if (SystemUtil.isServer()) {
hotWeapon.accuracyOfFireEnable = true;
// The maximum value of bullet offset half angle that affects shooting accuracy (range Min~88)
hotWeapon.accuracyOfFireComponent.maxDispersionHalfAngle = 4;
// The minimum value of offset half angle of bullet that affects shoot accuracy (range 0~Max)
hotWeapon.accuracyOfFireComponent.minDispersionHalfAngle = 0.01;
// Default offset half angle of bullet that affects shoot accuracy (range Min~Max)
hotWeapon.accuracyOfFireComponent.defaultDispersionHalfAngle = 1;
// The expansion speed per second of the bullet offset half angle that affects shooting accuracy (range 0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreaseSpeed = 5;
// The contraction speed per second (range 0~88) of bullet offset half angle that affects shooting accuracy
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleDecreaseSpeed = 10;
// Each firing expansion value of offset half angle of bullet that affects shoot accuracy (range 0~88)
hotWeapon.accuracyOfFireComponent.dispersionHalfAngleIncreasePerShot = 1;
} else if (SystemUtil.isClient()) {
hotWeapon.accuracyOfFireComponent.onCurrentDispersionChangedClient.add(() => { console.log("accuracyOfFireComponent.onCurrentDispersionChangedClient") });
}
}
}
Table of contents
Properties
onCurrentDispersionChange: MulticastDelegateInterface <() => void > |
---|
The binding function is executed when the actual shoot accuracy value of the client changes. |
Accessors
defaultDispersionHalfAngle(): number other |
---|
Get the default radius of the bullet's random divergence range. |
dispersionHalfAngleDecreaseSpeed(): number other |
Obtain the contraction speed of the random divergence radius of the bullet. |
dispersionHalfAngleIncreasePerShot(): number other |
Obtain the expansion value of the random divergence radius of the bullet after each shot. |
dispersionHalfAngleIncreaseSpeed(): number other |
Obtain the expansion speed of the random divergence radius of the bullet. |
maxDispersionHalfAngle(): number other |
Obtain the maximum radius of the random divergence range of bullets. |
minDispersionHalfAngle(): number other |
Obtain the minimum radius of the random divergence range of bullets. |
Methods
getCurrentDispersionHalfAngle(): number other |
---|
Obtain the actual value of the random divergence radius of the current bullet |
getRandomShootDir(shootDir : Vector ): Vector other |
Obtain the random shoot unit vector (in screen angle) in the conical space defined according to the shoot accuracy angle range |
getTargetDispersionHalfAngle(): number other |
Set the actual value of the radius of the random divergence range of target bullets |
Properties
onCurrentDispersionChange
• onCurrentDispersionChange: MulticastDelegateInterface
<() => void
>
The binding function is executed when the actual shoot accuracy value of the client changes.
Accessors
defaultDispersionHalfAngle
• | • | ||||
---|---|---|---|---|---|
Get the default radius of the bullet's random divergence range. Returns
| Sets the default radius of the bullet's random divergence range. Precautions Only the server can be called before equipping the hot weapon, and both ends can be called after equipping Parameters
|
dispersionHalfAngleDecreaseSpeed
• | • | ||||
---|---|---|---|---|---|
Obtain the contraction speed of the random divergence radius of the bullet. Returns
| Set the contraction speed of the random divergence radius of the bullet. Precautions Only the server can be called before equipping the hot weapon, and both ends can be called after equipping Parameters
|
dispersionHalfAngleIncreasePerShot
• | • | ||||
---|---|---|---|---|---|
Obtain the expansion value of the random divergence radius of the bullet after each shot. Returns
| Set the expansion value of the radius of the bullet's random divergence range after each shoot. Precautions Only the server can be called before equipping the hot weapon, and both ends can be called after equipping Parameters
|
dispersionHalfAngleIncreaseSpeed
• | • | ||||
---|---|---|---|---|---|
Obtain the expansion speed of the random divergence radius of the bullet. Returns
| Set the expansion speed of the random divergence radius of the bullet. Precautions Only the server can be called before equipping the hot weapon, and both ends can be called after equipping Parameters
|
maxDispersionHalfAngle
• | • | ||||
---|---|---|---|---|---|
Obtain the maximum radius of the random divergence range of bullets. Returns
| Set the maximum radius for the random divergence range of bullets. Precautions Only the server can be called before equipping the hot weapon, and both ends can be called after equipping Parameters
|
minDispersionHalfAngle
• | • | ||||
---|---|---|---|---|---|
Obtain the minimum radius of the random divergence range of bullets. Returns
| Set the minimum radius for the random divergence range of bullets. Precautions Only the server can be called before equipping the hot weapon, and both ends can be called after equipping Parameters
|
Methods
getCurrentDispersionHalfAngle
• getCurrentDispersionHalfAngle(): number
other
Obtain the actual value of the random divergence radius of the current bullet
Returns
number | Current bullet divergence range radius |
---|
getRandomShootDir
• getRandomShootDir(shootDir
): Vector
other
Obtain the random shoot unit vector (in screen angle) in the conical space defined according to the shoot accuracy angle range
Parameters
shootDir Vector | Initial bullet flight direction without deviation default: |
---|
Returns
Vector | Random screen offset coordinates |
---|
Generate bullets at the center of the screen and apply this vector directly
When generate bullets at the preset position, it is necessary to determine the impact point by the preset position+the vector+the maximum shoot distance, and then calculate the flight direction of bullets in the actual three-dimensional space
getTargetDispersionHalfAngle
• getTargetDispersionHalfAngle(): number
other
Set the actual value of the radius of the random divergence range of target bullets
Returns
number | Target bullet divergence radius |
---|