Created
June 12, 2022 20:15
-
-
Save eseidel/be5d5c10c4cf36ec18c8a38f8820ed1a to your computer and use it in GitHub Desktop.
Radiant + Flame
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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