Skip to main content

RandomDirectionInitializer Class

Initializer that configures spawned entities with random direction. More...

Declaration

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

Base class

classSpawnInitializer

Abstract interface for initializing spawned entity state. More...

Public Member Functions Index

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

Initializes entity with a random direction. More...

Description

Initializer that configures spawned entities with random direction.

RandomDirectionInitializer generates a random 2D direction and applies it to the entity's DirectionComponent and Move2DComponent. This is useful for spawning enemies that should move in unpredictable directions.

Components affected:

  • **DirectionComponent:** Sets random normalized direction
  • **Move2DComponent:** Sets move intent in the random direction
info

Uses a static Random generator with a fixed seed for reproducibility.

See Also

SpawnInitializer

Definition at line 35 of file RandomDirectionInitializer.ixx.

Public Member Functions

initialize()

void helios::engine::runtime::spawn::behavior::initializers::RandomDirectionInitializer::initialize (helios::engine::ecs::GameObject gameObject, const SpawnPlanCursor & cursor, const SpawnContext & spawnContext)
inline virtual

Initializes entity with a random direction.

Parameters
gameObject

The entity to initialize.

cursor

The current position within the spawn batch (unused).

spawnContext

Context data (unused).

Definition at line 46 of file RandomDirectionInitializer.ixx.

48 const SpawnPlanCursor& cursor,
49 const SpawnContext& spawnContext
50 ) override {
51
52 static auto rGen = helios::util::Random(12345);
53
56
57 auto dir = helios::math::vec2f{
58 rGen.randomFloat(-1.0f, 1.0f),
59 rGen.randomFloat(-1.0f, 1.0f)
60 };
61
62 dc->setDirection(dir.normalize().toVec3());
63 mc->move(dc->direction(), 1.0f);
64 }

References helios::engine::modules::physics::motion::components::Move2DComponent::direction, helios::engine::ecs::GameObject::get and helios::engine::modules::physics::motion::components::Move2DComponent::move.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.