ShootComponent Class
Component for handling projectile shooting with rate limiting. More...
Declaration
Public Constructors Index
| ShootComponent ()=default | |
|
Constructs a new ShootComponent with default settings. More... | |
| ShootComponent (const ShootComponent &)=default | |
| ShootComponent (ShootComponent &&) noexcept=default | |
Public Operators Index
| ShootComponent & | operator= (const ShootComponent &)=default |
| ShootComponent & | operator= (ShootComponent &&) noexcept=default |
Public Member Functions Index
| bool | isEnabled () const noexcept |
|
Checks whether this component is enabled. More... | |
| void | enable () noexcept |
|
Enables this component. More... | |
| void | disable () noexcept |
|
Disables this component. More... | |
| void | shoot (const float intensity, const helios::math::vec3f sourceVelocity) |
|
Sets the shooting intensity. More... | |
| float | cooldownDelta () const noexcept |
|
Returns the cooldown interval between shots. More... | |
| float | intensity () const noexcept |
|
Returns the current fire intensity. More... | |
| float | cooldownTimer () const noexcept |
|
Returns the accumulated time since last shot. More... | |
| void | setCooldownTimer (float cooldown) noexcept |
|
Sets the accumulated cooldown timer. More... | |
| void | updateCooldownTimerBy (float delta) noexcept |
|
Adds delta time to the cooldown timer. More... | |
| float | projectileSpeed () const noexcept |
|
Returns the projectile speed. More... | |
| void | setProjectileSpeed (float speed) noexcept |
|
Sets the projectile speed. More... | |
| helios::math::vec3f | sourceVelocity () const noexcept |
|
Returns the source object's velocity. More... | |
| float | fireRate () const noexcept |
|
Returns the fire rate in projectiles per second. More... | |
| void | setFireRate (const float fireRate) noexcept |
|
Sets the fire rate. More... | |
Protected Member Attributes Index
| float | intensity_ = 0.0f |
|
Current fire intensity (0.0 to 1.0). More... | |
| float | cooldownDelta_ = 0.0f |
|
Cooldown interval between shots, in seconds. More... | |
| float | cooldownTimer_ = 0.0f |
|
Accumulated time since last shot, in seconds. More... | |
| float | projectileSpeed_ = 60.0f |
|
The projectile speed, in meters per second. More... | |
| helios::math::vec3f | sourceVelocity_ |
|
Velocity of the source object in three-dimensional space. More... | |
| float | fireRate_ = 1.0f |
|
Fire rate per second, i.e. projectiles than can be shot per second. More... | |
| bool | isEnabled_ = true |
|
Whether this component is enabled. More... | |
Description
Component for handling projectile shooting with rate limiting.
Manages the shooting mechanics for a GameObject by coordinating with aim-components for direction and a projectile pool for projectile spawning. Implements a cooldown timer to control fire rate.
Example usage: ```cpp auto shootComponent = std::make_unique<ShootComponent>(); gameObject.add(std::move(shootComponent));
// Trigger shooting (typically from ShootCommand) shootComponent->shoot(1.0f); ```
Definition at line 38 of file ShootComponent.ixx.
Public Constructors
ShootComponent()
| default |
Constructs a new ShootComponent with default settings.
Definition at line 118 of file ShootComponent.ixx.
Referenced by operator=, operator=, ShootComponent and ShootComponent.
ShootComponent()
| default |
Definition at line 120 of file ShootComponent.ixx.
Reference ShootComponent.
ShootComponent()
| noexcept default |
Definition at line 122 of file ShootComponent.ixx.
Reference ShootComponent.
Public Operators
operator=()
| default |
Definition at line 121 of file ShootComponent.ixx.
Reference ShootComponent.
operator=()
| noexcept default |
Definition at line 123 of file ShootComponent.ixx.
Reference ShootComponent.
Public Member Functions
cooldownDelta()
| inline nodiscard noexcept |
Returns the cooldown interval between shots.
- Returns
Cooldown interval in seconds (derived from 1.0 / fireRate).
Definition at line 151 of file ShootComponent.ixx.
Reference cooldownDelta_.
cooldownTimer()
| inline nodiscard noexcept |
Returns the accumulated time since last shot.
- Returns
Accumulated cooldown timer in seconds.
Definition at line 169 of file ShootComponent.ixx.
Reference cooldownTimer_.
disable()
| inline noexcept |
enable()
| inline noexcept |
fireRate()
| inline nodiscard noexcept |
Returns the fire rate in projectiles per second.
- Returns
Fire rate (projectiles/second).
Definition at line 224 of file ShootComponent.ixx.
Reference fireRate_.
Referenced by setFireRate.
intensity()
| inline nodiscard noexcept |
Returns the current fire intensity.
- Returns
The intensity value (0.0 to 1.0).
Definition at line 160 of file ShootComponent.ixx.
Reference intensity_.
Referenced by shoot.
isEnabled()
| inline nodiscard noexcept |
Checks whether this component is enabled.
- Returns
True if enabled, false otherwise.
Definition at line 97 of file ShootComponent.ixx.
Reference isEnabled_.
projectileSpeed()
| inline nodiscard noexcept |
Returns the projectile speed.
- Returns
Projectile speed in meters per second.
Definition at line 196 of file ShootComponent.ixx.
Reference projectileSpeed_.
setCooldownTimer()
| inline noexcept |
Sets the accumulated cooldown timer.
- Parameters
-
cooldown New timer value in seconds.
Definition at line 178 of file ShootComponent.ixx.
Reference cooldownTimer_.
setFireRate()
| inline noexcept |
Sets the fire rate.
Updates the cooldown delta based on the new fire rate.
- Parameters
-
fireRate The number of projectiles per second. Must be greater than zero.
Definition at line 235 of file ShootComponent.ixx.
References cooldownDelta_, helios::math::EPSILON_LENGTH, fireRate and fireRate_.
setProjectileSpeed()
| inline noexcept |
Sets the projectile speed.
- Parameters
-
speed New projectile speed in meters per second.
Definition at line 205 of file ShootComponent.ixx.
Reference projectileSpeed_.
shoot()
| inline |
Sets the shooting intensity.
Call with a non-zero value to start shooting, or zero to stop. The intensity affects whether projectiles are spawned during update().
- Parameters
-
intensity Fire intensity (0.0 to 1.0). Zero stops firing.
sourceVelocity The velocity of the object emitting the projectile.
Definition at line 135 of file ShootComponent.ixx.
References helios::math::EPSILON_LENGTH, intensity, intensity_, shoot, sourceVelocity and sourceVelocity_.
Referenced by shoot.
sourceVelocity()
| inline nodiscard noexcept |
Returns the source object's velocity.
- Returns
Velocity vector used for projectile trajectory adjustment.
Definition at line 215 of file ShootComponent.ixx.
Reference sourceVelocity_.
Referenced by shoot.
updateCooldownTimerBy()
| inline noexcept |
Adds delta time to the cooldown timer.
- Parameters
-
delta Time to add in seconds.
Definition at line 187 of file ShootComponent.ixx.
Reference cooldownTimer_.
Protected Member Attributes
cooldownDelta_
| protected |
Cooldown interval between shots, in seconds.
Derived from fireRate (1.0 / fireRate). Determines the minimum time that must pass between consecutive projectile spawns.
Definition at line 56 of file ShootComponent.ixx.
Referenced by cooldownDelta and setFireRate.
cooldownTimer_
| protected |
Accumulated time since last shot, in seconds.
Accumulates delta time multiplied by intensity. When this value exceeds cooldownDelta, projectiles are spawned and the timer is reduced.
Definition at line 64 of file ShootComponent.ixx.
Referenced by cooldownTimer, setCooldownTimer and updateCooldownTimerBy.
fireRate_
| protected |
Fire rate per second, i.e. projectiles than can be shot per second.
Definition at line 83 of file ShootComponent.ixx.
Referenced by fireRate and setFireRate.
intensity_
| protected |
Current fire intensity (0.0 to 1.0).
Set by shoot() and cleared when intensity is zero. Controls whether projectiles are spawned during update().
Definition at line 48 of file ShootComponent.ixx.
isEnabled_
| protected |
Whether this component is enabled.
Definition at line 88 of file ShootComponent.ixx.
projectileSpeed_
| protected |
The projectile speed, in meters per second.
Definition at line 70 of file ShootComponent.ixx.
Referenced by projectileSpeed and setProjectileSpeed.
sourceVelocity_
| protected |
Velocity of the source object in three-dimensional space.
Used to adjust the trajectory of projectiles emitted by the source's movement.
Definition at line 77 of file ShootComponent.ixx.
Referenced by shoot and sourceVelocity.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.