Skip to main content

MoveInitializer Class

Initializer that sets movement direction for spawned entities. More...

Declaration

class helios::engine::runtime::spawn::behavior::initializers::MoveInitializer { ... }

Base class

classSpawnInitializer

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

voidinitialize (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor &cursor, const SpawnContext &spawnContext) override

Initializes the spawned entity's direction and movement. More...

voidonReset () noexcept override

Called when the spawn system is reset. More...

Private Member Functions Index

voidrandom (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor &cursor, const SpawnContext &spawnContext) noexcept

Applies a random direction to the entity. More...

voidalignTo (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::RandomrGen_ {12345}
const DirectionTypedirectionType_ = DirectionType::Random

The direction strategy to apply during initialization. More...

helios::math::vec3fdirection_ {}

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

SpawnInitializer

See Also

DirectionComponent

See Also

Move2DComponent

See Also

TranslationStateComponent

Definition at line 112 of file MoveInitializer.ixx.

Public Constructors

MoveInitializer()

helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::MoveInitializer (const DirectionType direction)
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.

220 explicit MoveInitializer(const DirectionType direction) : directionType_(direction) {}

MoveInitializer()

helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::MoveInitializer (const helios::math::vec3f directionAxis)
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.

230 explicit MoveInitializer(const helios::math::vec3f directionAxis) : directionType_(DirectionType::Axis), direction_(directionAxis) {}

MoveInitializer()

helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::MoveInitializer (const helios::math::vec3f target, const DirectionType direction)
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.

242 explicit MoveInitializer(const helios::math::vec3f target, const DirectionType direction) : directionType_(direction), direction_(target) {}

Public Member Functions

initialize()

void helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::initialize (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor & cursor, const SpawnContext & spawnContext)
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.

257 const SpawnPlanCursor& cursor,
258 const SpawnContext& spawnContext
259 ) override {
260
261 switch (directionType_) {
263 random(gameObject, cursor, spawnContext);
264 return;
266 alignTo(gameObject, cursor, spawnContext, helios::math::X_AXISf);
267 return;
269 alignTo(gameObject, cursor, spawnContext, helios::math::X_AXISf * -1.0f);
270 return;
272 alignTo(gameObject, cursor, spawnContext, direction_);
273 return;
274
276 alignTo(gameObject, cursor, spawnContext, direction_, directionType_);
277 return;
278 }
279 }

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()

void helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::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.

281 void onReset() noexcept override {
282 rGen_.reset();
283 }

Private Member Functions

alignTo()

void helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::alignTo (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor & cursor, const SpawnContext & spawnContext, const helios::math::vec3f target, const DirectionType directionType=DirectionType::Axis)
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.

181 void alignTo (
183 const SpawnPlanCursor& cursor,
184 const SpawnContext& spawnContext,
185 const helios::math::vec3f target,
186 const DirectionType directionType = DirectionType::Axis
187
188 ) noexcept {
189
193
194 auto direction = target;
195 if (directionType == DirectionType::Axis) {
196 assert(direction.isNormalized() && "axis initializer requires valid direction vector");
197 } else if (directionType == DirectionType::Point) {
199
200 direction = (target - (tsc->translation() * -1.0f)).normalize();
201 assert(direction.isNormalized() && "point initializer requires valid direction vector");
202 }
203
204 dc->setDirection(direction);
205
206 sc->setTargetRotationAngle(helios::math::degrees(std::atan2(direction[1], direction[0])));
207 sc->setCurrentRotationAngle(helios::math::degrees(std::atan2(direction[1], direction[0])));
208
209 mc->move(direction, 1.0f);
210
211
212 }

random()

void helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::random (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor & cursor, const SpawnContext & spawnContext)
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.

140 void random(
142 const SpawnPlanCursor& cursor,
143 const SpawnContext& spawnContext
144 ) noexcept {
145
148
149 auto dir = helios::math::vec2f{
150 rGen_.randomFloat(-1.0f, 1.0f),
151 rGen_.randomFloat(-1.0f, 1.0f)
152 };
154 if (sc) {
155 sc->setTargetRotationAngle(helios::math::degrees(std::atan2(dir[1], dir[0])));
156 sc->setCurrentRotationAngle(helios::math::degrees(std::atan2(dir[1], dir[0])));
157 }
158
159 dc->setDirection(dir.normalize().toVec3());
160 mc->move(dc->direction(), 1.0f);
161 }

Private Member Attributes

direction_

helios::math::vec3f helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::direction_ {}

Stores the custom direction target (axis/point) when using DirectionType::Axis/::Point.

Definition at line 124 of file MoveInitializer.ixx.

124 helios::math::vec3f direction_{};

directionType_

const DirectionType helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::directionType_ = DirectionType::Random

The direction strategy to apply during initialization.

Definition at line 119 of file MoveInitializer.ixx.

119 const DirectionType directionType_ = DirectionType::Random;

rGen_

helios::util::Random helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::rGen_ {12345}

Definition at line 114 of file MoveInitializer.ixx.

114 helios::util::Random rGen_{12345};

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.