Follow is a behavior node which enables the prefab to follow its leader. The Follow behavior encompasses two actions : back off and approach. During following, the prefab tries to maintain a target distance between itself and its target. When the distance is smaller than a min distance, the prefab will choose to back off. When it is larger than a max distance, the prefab will choose to approach.
|target||function or table||Target entity that the prefab is trying to follow|
|min_dist||integer||minimum distance before prefab begins to back off|
|target_dist||integer||The desired distance the prefab try to maintain from the leader|
|max_dist||integer||maximum distance before prefab begins to approach|
|canrun||bool||(optional) used to determine if the prefab need to run|
The three distances(min_dist, target_dist, max_dist) are used for the prefab to determine its action during Follow behavior. Noticeably, when the distance between prefab and its target is between min_dist and max_dist, the follow behavior will be in a failed state. (the behavior is not activated)
Follow State Diagram
The Follow Behavior has 4 states: Ready, Running, Failed,Success.
Follow(self.inst, function() return self.inst.components.follower and self.inst.components.follower.leader end, MIN_FOLLOW_DIST, TARGET_FOLLOW_DIST, MAX_FOLLOW_DIST),
FaceEntity(self.inst, GetFaceTargetFn, KeepFaceTargetFn),