Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Flame behaviors used to organically manage the movement of an entity. Built by Very Good Ventures 🦄

License

Notifications You must be signed in to change notification settings

VeryGoodOpenSource/flame_steering_behaviors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Steering Behaviors

Very Good Ventures Very Good Ventures

Developed with 💙 by Very Good Ventures 🦄

ci coverage pub package style: very good analysis License: MIT Powered by Flame


An implementation of steering behaviors for Flame Behaviors. See Steering Behaviors For Autonomous Characters by Craig Reynolds for an in-depth explanation


Installation 💻

flutter pub add flame_steering_behaviors

Usage ✨

This package is built on top of the flame_behaviors, if you are not yet familiar with it, we recommend reading up on the documentation of that package first.

Steerable

If you want to apply steering behaviors to your entities you have to add the Steerable mixin to your entity class:

class MyEntity extends Entity with Steerable {
  /// Provide the max velocity this entity can hold.
  double get maxVelocity => 100;

  ...
}

The Steerable mixin provides a velocity value to your entity, this velocity will then be applied on each update cycle to your entity until the velocity becomes zero.

Steering Behaviors

Each algorithm defined by this project is available as a Behavior and you can add them to your steerable entities as you would with any behavior:

class MyEntity extends Entity with Steerable {
  MyEntity() : super(
    behaviors: [
      WanderBehavior(
        circleDistance: 200,
        maximumAngle: 45 * degrees2Radians,
        startingAngle: 0,
      )
    ]
  );

  ...
}

Some steering behaviors require information that is not always available on entity creation, when that happens we recommend using the entity's onLoad method:

class MyEntity extends Entity with Steerable {
  ...

  @override
  Future<void> onLoad() async {
    world.children.register<MyOtherEntity>();
    await add(
      SeparationBehavior(
        world.children.query<MyOtherEntity>(),
        maxDistance: 25,
        maxAcceleration: 1000,
      ),
    );
  }

  ...
}

About

Flame behaviors used to organically manage the movement of an entity. Built by Very Good Ventures 🦄

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages