MoveInitializer Class
Initializer that sets movement direction for spawned entities. More...
Declaration
Base class
| class | SpawnInitializer |
|
Abstract interface for initializing spawned entity state. More... | |
Public Constructors Index
| MoveInitializer (const DirectionType direction) | |
|
Constructs a MoveInitializer with the specified strategy. More... | |
| MoveInitializer (const helios::math::vec3f directionAxis) | |
|
Constructs a MoveInitializer with a custom axis. More... | |
| MoveInitializer (const helios::math::vec3f target, const DirectionType direction) | |
|
Constructs a MoveInitializer with a target point or axis and explicit strategy. More... | |
Public Member Functions Index
| void | initialize (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor &cursor, const SpawnContext &spawnContext) override |
|
Initializes the spawned entity's direction and movement. More... | |
| void | onReset () noexcept override |
|
Called when the spawn system is reset. More... | |
Private Member Functions Index
| void | random (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor &cursor, const SpawnContext &spawnContext) noexcept |
|
Applies a random direction to the entity. More... | |
| void | alignTo (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor &cursor, const SpawnContext &spawnContext, const helios::math::vec3f target, const DirectionType directionType=DirectionType::Axis) noexcept |
|
Aligns the entity's movement direction to a target axis or point. More... | |
Private Member Attributes Index
| helios::util::Random | rGen_ {12345} |
| const DirectionType | directionType_ = DirectionType::Random |
|
The direction strategy to apply during initialization. More... | |
| helios::math::vec3f | direction_ {} |
|
Stores the custom direction target (axis/point) when using DirectionType::Axis/::Point. More... | |
Description
Initializer that sets movement direction for spawned entities.
MoveInitializer configures the DirectionComponent and Move2DComponent of spawned entities based on the specified DirectionType strategy. This determines the initial movement vector of the entity.
## Direction Strategies
- **Random:** Generates a random normalized 2D direction using a seeded RNG.
- **Right:** Sets direction to positive X-axis (1, 0, 0).
- **Left:** Sets direction to negative X-axis (-1, 0, 0).
- **Axis:** Sets direction to a custom provided axis vector.
- **Point:** Calculates direction toward a specific target point.
## Required Components
Spawned entities must have:
- `DirectionComponent` - receives the calculated direction.
- `Move2DComponent` - receives the move command with direction.
- `SteeringComponent` (Optional) - receives the rotation looking at direction.
- `TranslationStateComponent` (Required for `Point` strategy) - provides current position.
## Usage Examples
Random direction: ```cpp auto initializer = std::make_unique<MoveInitializer>(DirectionType::Random); spawnProfile.spawnInitializer = std::move(initializer); ```
Custom axis direction: ```cpp auto axis = helios::math::vec3f{0.707f, 0.707f, 0.0f}; // 45 degrees auto initializer = std::make_unique<MoveInitializer>(axis); ```
Direction toward a target point: ```cpp auto target = helios::math::vec3f{100.0f, 50.0f, 0.0f}; auto initializer = std::make_unique<MoveInitializer>(target, DirectionType::Point); ```
- See Also
- See Also
DirectionComponent
- See Also
Move2DComponent
- See Also
TranslationStateComponent
Definition at line 112 of file MoveInitializer.ixx.
Public Constructors
MoveInitializer()
| inline explicit |
Constructs a MoveInitializer with the specified strategy.
- Parameters
-
direction The direction strategy to use during initialization.
Definition at line 220 of file MoveInitializer.ixx.
MoveInitializer()
| inline explicit |
Constructs a MoveInitializer with a custom axis.
Sets the strategy to `DirectionType::Axis` and stores the provided axis vector.
- Parameters
-
directionAxis The custom direction vector to use.
Definition at line 230 of file MoveInitializer.ixx.
MoveInitializer()
| inline explicit |
Constructs a MoveInitializer with a target point or axis and explicit strategy.
Allows specifying both a target vector and the direction strategy. Use `DirectionType::Point` to calculate direction toward the target point, or `DirectionType::Axis` to use the vector as a direct direction.
- Parameters
-
target The target point or axis vector.
direction The direction strategy to use.
Definition at line 242 of file MoveInitializer.ixx.
Public Member Functions
initialize()
| inline virtual |
Initializes the spawned entity's direction and movement.
Delegates to the appropriate strategy method based on the configured Direction enum value.
- Parameters
-
gameObject The spawned entity to initialize.
cursor The spawn plan cursor providing batch context.
spawnContext The spawn context with emitter information.
Definition at line 255 of file MoveInitializer.ixx.
References helios::engine::runtime::spawn::behavior::initializers::Axis, helios::engine::runtime::spawn::behavior::initializers::Left, helios::engine::runtime::spawn::behavior::initializers::Point, helios::engine::runtime::spawn::behavior::initializers::Random, helios::engine::runtime::spawn::behavior::initializers::Right and helios::math::X_AXISf.
onReset()
| inline noexcept virtual |
Called when the spawn system is reset.
Override to reset any internal state (e.g., RNG seeds). The default implementation is a no-op.
Definition at line 281 of file MoveInitializer.ixx.
Private Member Functions
alignTo()
| inline noexcept |
Aligns the entity's movement direction to a target axis or point.
Depending on the directionType parameter:
- **Axis:** Sets the entity's direction to the provided normalized vector.
- **Point:** Calculates the direction from the entity's current position to the target point and normalizes it.
In both cases, triggers a move command with full throttle (1.0) and updates the SteeringComponent to rotate the entity toward the movement direction.
- Parameters
-
gameObject The spawned entity to initialize.
cursor The spawn plan cursor (unused).
spawnContext The spawn context (unused).
target The target axis vector or point coordinates.
directionType The direction strategy (`Axis` or `Point`).
Definition at line 181 of file MoveInitializer.ixx.
random()
| inline noexcept |
Applies a random direction to the entity.
Generates a random 2D vector, normalizes it, and sets it as the entity's direction. Also triggers a move command with full throttle (1.0).
If a SteeringComponent is present, the entity is rotated to face the movement direction.
- Parameters
-
gameObject The spawned entity to initialize.
cursor The spawn plan cursor (unused).
spawnContext The spawn context (unused).
Definition at line 140 of file MoveInitializer.ixx.
Private Member Attributes
direction_
|
Stores the custom direction target (axis/point) when using DirectionType::Axis/::Point.
Definition at line 124 of file MoveInitializer.ixx.
directionType_
|
The direction strategy to apply during initialization.
Definition at line 119 of file MoveInitializer.ixx.
rGen_
|
Definition at line 114 of file MoveInitializer.ixx.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.