seeAndMoveToPlayer method
Shape?
seeAndMoveToPlayer({
- required dynamic closePlayer(),
- VoidCallback? notObserved,
- VoidCallback? observed,
- VoidCallback? notCanMove,
- double radiusVision = 32,
- double margin = 10,
- double? visionAngle,
- double? angle,
- bool runOnlyVisibleInScreen = true,
Checks whether the player is within range. If so, move to it.
visionAngle
in radians
angle
in radians. is automatically picked up using the component's direction.
Implementation
Shape? seeAndMoveToPlayer({
required Function(Player) closePlayer,
VoidCallback? notObserved,
VoidCallback? observed,
VoidCallback? notCanMove,
double radiusVision = 32,
double margin = 10,
double? visionAngle,
double? angle,
bool runOnlyVisibleInScreen = true,
}) {
if (runOnlyVisibleInScreen && !isVisible) return null;
return seePlayer(
radiusVision: radiusVision,
visionAngle: visionAngle,
angle: angle,
observed: (player) {
observed?.call();
bool move = followComponent(
player,
dtUpdate,
closeComponent: (comp) => closePlayer(comp as Player),
margin: margin,
);
if (!move) {
notCanMove?.call();
}
},
notObserved: () {
if (!isIdle) {
idle();
}
notObserved?.call();
},
);
}