Move2DComponent Class
Component for 2D physics-based movement. More...
Declaration
Public Constructors Index
| Move2DComponent ()=default | |
|
Default constructor with default physics parameters. More... | |
| Move2DComponent (float movementSpeed, float movementAcceleration=DEFAULT_MOVEMENT_ACCELERATION) | |
|
Constructs a Move2DComponent with a specified movement speed. More... | |
| Move2DComponent (float movementSpeed, bool useInstantAcceleration) | |
|
Constructs a Move2DComponent with instant acceleration mode. More... | |
| Move2DComponent (const Move2DComponent &other) | |
|
Copy constructor. More... | |
| Move2DComponent (Move2DComponent &&) noexcept=default | |
Public Operators Index
| Move2DComponent & | operator= (const Move2DComponent &)=default |
| Move2DComponent & | operator= (Move2DComponent &&) 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 | move (helios::math::vec3f direction, float throttle) |
|
Sets the movement direction and throttle. More... | |
| void | setMoveIntent (helios::math::vec3f direction, float throttle) |
|
Sets the movement direction and throttle. More... | |
| void | reset () |
|
Resets this component's properties to default values. More... | |
| void | onAcquire () noexcept |
| void | onRelease () noexcept |
| bool | useInstantAcceleration () const noexcept |
|
Returns whether instant acceleration mode is enabled. More... | |
| void | setUseInstantAcceleration (const bool useInstantAcceleration) noexcept |
|
Sets the instant acceleration mode. More... | |
| void | setInheritedVelocity (helios::math::vec3f inheritedVelocity) |
|
Sets the inherited velocity from parent or external forces. More... | |
| helios::math::vec3f | inheritedVelocity () const noexcept |
|
Returns the inherited velocity vector. More... | |
| void | setVelocity (helios::math::vec3f velocity) noexcept |
|
Sets the current velocity vector. More... | |
| float | currentMovementSpeed () const noexcept |
|
Returns the current movement speed. More... | |
| void | setCurrentMovementSpeed (float speed) noexcept |
|
Sets the current movement speed. More... | |
| bool | stateChanged () const noexcept |
|
Checks if input is currently active. More... | |
| const helios::math::vec2f & | direction () const noexcept |
|
Returns the current steering input direction. More... | |
| float | throttle () const noexcept |
|
Returns the current throttle value (0.0 to 1.0). More... | |
| const helios::math::vec3f & | velocity () const noexcept |
|
Returns the current velocity vector. More... | |
| float | speedRatio () const noexcept |
|
Returns the current speed as a ratio of maximum speed. More... | |
| float | movementSpeedThreshold () const noexcept |
|
Returns the minimum movement speed threshold. More... | |
| float | movementAcceleration () const noexcept |
|
Returns the movement acceleration in units per second squared. More... | |
| float | movementSpeed () const noexcept |
|
Returns the maximum movement speed in units per second. More... | |
| float | movementDampening () const noexcept |
|
Returns the movement dampening factor. More... | |
| void | setMovementSpeedThreshold (float value) noexcept |
|
Sets the minimum movement speed threshold. More... | |
| void | setMovementAcceleration (float value) noexcept |
|
Sets the movement acceleration in units per second squared. More... | |
| void | setMovementSpeed (float value) noexcept |
|
Sets the maximum movement speed in units per second. More... | |
| void | setMovementDampening (float value) noexcept |
|
Sets the movement dampening factor. More... | |
| void | resetToDefaults () noexcept |
|
Resets all physics parameters to their default values. More... | |
Protected Member Attributes Index
| float | movementSpeedThreshold_ = DEFAULT_MOVEMENT_SPEED_THRESHOLD |
|
Minimum movement speed before the ship stops completely. More... | |
| float | movementAcceleration_ = DEFAULT_MOVEMENT_ACCELERATION |
|
Movement acceleration in units per second squared. More... | |
| float | movementSpeed_ = DEFAULT_MOVEMENT_SPEED |
|
Base movement speed in units per second. More... | |
| float | movementDampening_ = DEFAULT_MOVEMENT_DAMPENING |
|
Exponential decay factor for movement when input stops. More... | |
| float | currentMovementSpeed_ = 0.0f |
|
Current movement speed after applying input and dampening. More... | |
| bool | stateChanged_ = true |
|
Indicates whether input is currently being received. More... | |
| float | throttle_ = 0.0f |
|
Current throttle value from input (0.0 to 1.0). More... | |
| helios::math::vec2f | direction_ |
|
Current steering input as 2D direction vector. More... | |
| helios::math::vec3f | velocity_ |
|
Current velocity vector in world space. More... | |
| helios::math::vec3f | inheritedVelocity_ {0.0f} |
|
Inherited velocity from parent or external forces. More... | |
| bool | useInstantAcceleration_ = false |
|
Flag for instant acceleration mode. More... | |
| bool | isEnabled_ = true |
|
Whether this component is enabled. More... | |
Protected Static Attributes Index
| static constexpr float | DEFAULT_MOVEMENT_SPEED_THRESHOLD = 0.1f |
|
Default minimum movement speed before the ship stops completely. More... | |
| static constexpr float | DEFAULT_MOVEMENT_ACCELERATION = 30.0f |
|
Default movement acceleration in units per second squared. More... | |
| static constexpr float | DEFAULT_MOVEMENT_SPEED = 30.0f |
|
Default base movement speed in units per second. More... | |
| static constexpr float | DEFAULT_MOVEMENT_DAMPENING = 0.1f |
|
Default exponential decay factor for movement when input stops. More... | |
Description
Component for 2D physics-based movement.
Stores configuration and runtime state for 2D physics-based movement. This component is used by the Move2DSystem to apply smooth acceleration and deceleration to the entity.
The component receives input via move() which sets target direction and throttle. The actual physics simulation (integration of velocity, application of dampening) is performed by the Move2DSystem.
Rotation/heading is handled separately by SteeringComponent and SteeringSystem.
- See Also
helios::engine::modules::physics::systems::Move2DSystem
Definition at line 43 of file Move2DComponent.ixx.
Public Constructors
Move2DComponent()
| default |
Default constructor with default physics parameters.
Definition at line 179 of file Move2DComponent.ixx.
Referenced by Move2DComponent, Move2DComponent, operator= and operator=.
Move2DComponent()
| inline explicit |
Constructs a Move2DComponent with a specified movement speed.
- Parameters
-
movementSpeed The maximum movement speed in units per second.
movementAcceleration The acceleration rate (default: DEFAULT_MOVEMENT_ACCELERATION).
Definition at line 187 of file Move2DComponent.ixx.
References DEFAULT_MOVEMENT_ACCELERATION, movementAcceleration, movementAcceleration_, movementSpeed and movementSpeed_.
Move2DComponent()
| inline explicit |
Constructs a Move2DComponent with instant acceleration mode.
- Parameters
-
movementSpeed The maximum movement speed in units per second.
useInstantAcceleration If true, acceleration is instant.
Definition at line 200 of file Move2DComponent.ixx.
References movementSpeed, movementSpeed_, useInstantAcceleration and useInstantAcceleration_.
Move2DComponent()
| inline |
Copy constructor.
- Parameters
-
other The component to copy from.
Definition at line 212 of file Move2DComponent.ixx.
References Move2DComponent, movementAcceleration_, movementDampening_, movementSpeed_, movementSpeedThreshold_ and useInstantAcceleration_.
Move2DComponent()
| noexcept default |
Definition at line 221 of file Move2DComponent.ixx.
Reference Move2DComponent.
Public Operators
operator=()
| default |
Definition at line 220 of file Move2DComponent.ixx.
Reference Move2DComponent.
operator=()
| noexcept default |
Definition at line 222 of file Move2DComponent.ixx.
Reference Move2DComponent.
Public Member Functions
currentMovementSpeed()
| inline nodiscard noexcept |
Returns the current movement speed.
- Returns
The current movement speed.
Definition at line 342 of file Move2DComponent.ixx.
Reference currentMovementSpeed_.
direction()
| inline nodiscard noexcept |
Returns the current steering input direction.
- Returns
Const reference to the 2D steering input vector.
Definition at line 369 of file Move2DComponent.ixx.
Reference direction_.
Referenced by helios::engine::runtime::spawn::behavior::initializers::RandomDirectionInitializer::initialize, move and setMoveIntent.
disable()
| inline noexcept |
enable()
| inline noexcept |
inheritedVelocity()
| inline nodiscard noexcept |
Returns the inherited velocity vector.
- Returns
The inherited velocity from parent or external forces.
Definition at line 324 of file Move2DComponent.ixx.
Reference inheritedVelocity_.
Referenced by setInheritedVelocity.
isEnabled()
| inline nodiscard noexcept |
Checks whether this component is enabled.
- Returns
True if enabled, false otherwise.
Definition at line 158 of file Move2DComponent.ixx.
Reference isEnabled_.
move()
| inline |
Sets the movement direction and throttle.
- Parameters
-
direction Normalized 3D direction vector.
throttle Magnitude of the stick input (0.0 to 1.0).
- Deprecated
-
use setMoveIntent
Definition at line 233 of file Move2DComponent.ixx.
References direction, move, setMoveIntent and throttle.
Referenced by helios::engine::runtime::spawn::behavior::initializers::RandomDirectionInitializer::initialize and move.
movementAcceleration()
| inline nodiscard noexcept |
Returns the movement acceleration in units per second squared.
- Returns
Movement acceleration value.
Definition at line 420 of file Move2DComponent.ixx.
Reference movementAcceleration_.
Referenced by Move2DComponent.
movementDampening()
| inline nodiscard noexcept |
Returns the movement dampening factor.
- Returns
Exponential decay factor for movement.
Definition at line 434 of file Move2DComponent.ixx.
Reference movementDampening_.
movementSpeed()
| inline nodiscard noexcept |
Returns the maximum movement speed in units per second.
- Returns
Maximum movement speed value.
Definition at line 427 of file Move2DComponent.ixx.
Reference movementSpeed_.
Referenced by Move2DComponent and Move2DComponent.
movementSpeedThreshold()
| inline nodiscard noexcept |
Returns the minimum movement speed threshold.
- Returns
Movement speed threshold below which movement stops.
Definition at line 413 of file Move2DComponent.ixx.
Reference movementSpeedThreshold_.
onAcquire()
| inline noexcept |
onRelease()
| inline noexcept |
reset()
| inline |
Resets this component's properties to default values.
Definition at line 265 of file Move2DComponent.ixx.
References currentMovementSpeed_, direction_, inheritedVelocity_, stateChanged_, throttle_ and velocity_.
resetToDefaults()
| inline noexcept |
Resets all physics parameters to their default values.
Definition at line 477 of file Move2DComponent.ixx.
References DEFAULT_MOVEMENT_ACCELERATION, DEFAULT_MOVEMENT_DAMPENING, DEFAULT_MOVEMENT_SPEED, DEFAULT_MOVEMENT_SPEED_THRESHOLD, movementAcceleration_, movementDampening_, movementSpeed_ and movementSpeedThreshold_.
setCurrentMovementSpeed()
| inline noexcept |
Sets the current movement speed.
- Parameters
-
speed The new movement speed.
Definition at line 351 of file Move2DComponent.ixx.
Reference currentMovementSpeed_.
setInheritedVelocity()
| inline |
Sets the inherited velocity from parent or external forces.
- Parameters
-
inheritedVelocity The velocity vector to inherit.
Definition at line 315 of file Move2DComponent.ixx.
References inheritedVelocity and inheritedVelocity_.
setMoveIntent()
| inline |
Sets the movement direction and throttle.
- Parameters
-
direction Normalized 3D direction vector.
throttle Magnitude of the stick input (0.0 to 1.0).
Definition at line 243 of file Move2DComponent.ixx.
References currentMovementSpeed_, direction, direction_, helios::math::EPSILON_LENGTH, movementSpeed_, stateChanged_, throttle and throttle_.
Referenced by move.
setMovementAcceleration()
| inline noexcept |
Sets the movement acceleration in units per second squared.
- Parameters
-
value New acceleration value.
Definition at line 454 of file Move2DComponent.ixx.
Reference movementAcceleration_.
setMovementDampening()
| inline noexcept |
Sets the movement dampening factor.
- Parameters
-
value New dampening factor (exponential decay).
Definition at line 468 of file Move2DComponent.ixx.
Reference movementDampening_.
setMovementSpeed()
| inline noexcept |
Sets the maximum movement speed in units per second.
- Parameters
-
value New maximum speed value.
Definition at line 461 of file Move2DComponent.ixx.
Reference movementSpeed_.
setMovementSpeedThreshold()
| inline noexcept |
Sets the minimum movement speed threshold.
- Parameters
-
value New threshold value.
Definition at line 446 of file Move2DComponent.ixx.
Reference movementSpeedThreshold_.
setUseInstantAcceleration()
| inline noexcept |
Sets the instant acceleration mode.
- Parameters
-
useInstantAcceleration True to enable instant acceleration, false for smooth ramping.
Definition at line 306 of file Move2DComponent.ixx.
References useInstantAcceleration and useInstantAcceleration_.
setVelocity()
| inline noexcept |
Sets the current velocity vector.
- Parameters
-
velocity The new velocity vector.
Definition at line 333 of file Move2DComponent.ixx.
speedRatio()
| inline nodiscard noexcept |
Returns the current speed as a ratio of maximum speed.
- Returns
A value between 0.0 (stationary) and 1.0 (maximum speed).
Definition at line 396 of file Move2DComponent.ixx.
References helios::math::EPSILON_LENGTH, movementSpeed_ and velocity_.
stateChanged()
| inline nodiscard noexcept |
Checks if input is currently active.
- Returns
True if input is active, false otherwise.
Definition at line 360 of file Move2DComponent.ixx.
Reference stateChanged_.
throttle()
| inline nodiscard noexcept |
Returns the current throttle value (0.0 to 1.0).
- Returns
Current throttle magnitude from input.
Definition at line 378 of file Move2DComponent.ixx.
Reference throttle_.
Referenced by move and setMoveIntent.
useInstantAcceleration()
| inline nodiscard noexcept |
Returns whether instant acceleration mode is enabled.
- Returns
True if acceleration is instant, false for smooth ramping.
Definition at line 297 of file Move2DComponent.ixx.
Reference useInstantAcceleration_.
Referenced by Move2DComponent and setUseInstantAcceleration.
velocity()
| inline nodiscard noexcept |
Returns the current velocity vector.
- Returns
Const reference to the 3D velocity vector in world space.
Definition at line 387 of file Move2DComponent.ixx.
Reference velocity_.
Referenced by setVelocity.
Protected Member Attributes
currentMovementSpeed_
| protected |
Current movement speed after applying input and dampening.
Definition at line 108 of file Move2DComponent.ixx.
Referenced by currentMovementSpeed, reset, setCurrentMovementSpeed and setMoveIntent.
direction_
| protected |
Current steering input as 2D direction vector.
Definition at line 124 of file Move2DComponent.ixx.
Referenced by direction, reset and setMoveIntent.
inheritedVelocity_
| protected |
Inherited velocity from parent or external forces.
Used for momentum inheritance when detaching from parent objects.
Definition at line 136 of file Move2DComponent.ixx.
Referenced by inheritedVelocity, reset and setInheritedVelocity.
isEnabled_
| protected |
Whether this component is enabled.
Definition at line 149 of file Move2DComponent.ixx.
movementAcceleration_
| protected |
Movement acceleration in units per second squared.
Definition at line 88 of file Move2DComponent.ixx.
Referenced by Move2DComponent, Move2DComponent, movementAcceleration, resetToDefaults and setMovementAcceleration.
movementDampening_
| protected |
Exponential decay factor for movement when input stops.
Definition at line 99 of file Move2DComponent.ixx.
Referenced by Move2DComponent, movementDampening, resetToDefaults and setMovementDampening.
movementSpeed_
| protected |
Base movement speed in units per second.
Definition at line 93 of file Move2DComponent.ixx.
Referenced by Move2DComponent, Move2DComponent, Move2DComponent, movementSpeed, resetToDefaults, setMoveIntent, setMovementSpeed and speedRatio.
movementSpeedThreshold_
| protected |
Minimum movement speed before the ship stops completely.
Definition at line 83 of file Move2DComponent.ixx.
Referenced by Move2DComponent, movementSpeedThreshold, resetToDefaults and setMovementSpeedThreshold.
stateChanged_
| protected |
Indicates whether input is currently being received.
Definition at line 113 of file Move2DComponent.ixx.
Referenced by reset, setMoveIntent and stateChanged.
throttle_
| protected |
Current throttle value from input (0.0 to 1.0).
Definition at line 119 of file Move2DComponent.ixx.
Referenced by reset, setMoveIntent and throttle.
useInstantAcceleration_
| protected |
Flag for instant acceleration mode.
When true, the entity accelerates instantly to target speed rather than smoothly ramping up.
Definition at line 144 of file Move2DComponent.ixx.
Referenced by Move2DComponent, Move2DComponent, setUseInstantAcceleration and useInstantAcceleration.
velocity_
| protected |
Current velocity vector in world space.
Definition at line 129 of file Move2DComponent.ixx.
Referenced by reset, setVelocity, speedRatio and velocity.
Protected Static Attributes
DEFAULT_MOVEMENT_ACCELERATION
| constexpr protected static |
Default movement acceleration in units per second squared.
Definition at line 62 of file Move2DComponent.ixx.
Referenced by Move2DComponent and resetToDefaults.
DEFAULT_MOVEMENT_DAMPENING
| constexpr protected static |
Default exponential decay factor for movement when input stops.
Definition at line 73 of file Move2DComponent.ixx.
Referenced by resetToDefaults.
DEFAULT_MOVEMENT_SPEED
| constexpr protected static |
Default base movement speed in units per second.
Definition at line 67 of file Move2DComponent.ixx.
Referenced by resetToDefaults.
DEFAULT_MOVEMENT_SPEED_THRESHOLD
| constexpr protected static |
Default minimum movement speed before the ship stops completely.
Definition at line 56 of file Move2DComponent.ixx.
Referenced by resetToDefaults.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.