Skip to content

Instantly share code, notes, and snippets.

@eseidel
Created June 12, 2022 20:15
Show Gist options
  • Save eseidel/be5d5c10c4cf36ec18c8a38f8820ed1a to your computer and use it in GitHub Desktop.
Save eseidel/be5d5c10c4cf36ec18c8a38f8820ed1a to your computer and use it in GitHub Desktop.
Radiant + Flame
class NavigationComponent extends Component with Steerable {
@override
Vector2 get position => positionParent?.position ?? Vector2.zero();
@override
Vector2 velocity = Vector2.zero();
@override
double get angle => positionParent?.angle ?? 0;
@override
double angularVelocity = 0;
@override
Kinematics kinematics = LightKinematics(10);
PositionComponent? get positionParent => parent as PositionComponent;
@override
set angle(double value) => positionParent!.angle = value;
Behavior? behavior;
void moveTo(Vector2 target) {
behavior = kinematics.seek(target);
}
@override
void onMount() {
kinematics.handleAttach(this);
super.onMount();
}
@override
void update(double dt) {
if (parent == null || behavior == null) {
return;
}
behavior!.update(dt);
super.update(dt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment