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...

voidonReset () noexcept override

Resets the random number generator to its initial seed. More...

Private Member Attributes Index

helios::util::RandomrGen_ {12345}

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 36 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 49 of file RandomDirectionInitializer.ixx.

51 const SpawnPlanCursor& cursor,
52 const SpawnContext& spawnContext
53 ) override {
54
55
58
59 auto dir = helios::math::vec2f{
60 rGen_.randomFloat(-1.0f, 1.0f),
61 rGen_.randomFloat(-1.0f, 1.0f)
62 };
63
64 dc->setDirection(dir.normalize().toVec3());
65 mc->move(dc->direction(), 1.0f);
66 }

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

onReset()

void helios::engine::runtime::spawn::behavior::initializers::RandomDirectionInitializer::onReset ()
inline noexcept virtual

Resets the random number generator to its initial seed.

Definition at line 71 of file RandomDirectionInitializer.ixx.

71 void onReset() noexcept override {
72 rGen_.reset();
73 }

Private Member Attributes

rGen_

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

Definition at line 38 of file RandomDirectionInitializer.ixx.

38 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.