'GKGoal toSeekAgent overrules other goals in GKBehavior
I have a few sets of GKGoals for different GKBehaviors. The all work fine until toSeekAgent or toInterceptAgent are added to the set. If present any toAvoid goal is completely ignored.
This works like a charm and the agent is wandering about not touching any obstacles.
init(targetSpeed: Float, avoid: [GKAgent], obstacles: [GKObstacle]) {
super.init()
setWeight(0.9, for: GKGoal(toWander: 100))
setWeight(1.0, for: GKGoal(toReachTargetSpeed: targetSpeed))
setWeight(1.0, for: GKGoal(toAvoid: obstacles, maxPredictionTime: 2.0))
setWeight(0.5, for: GKGoal(toAvoid: avoid, maxPredictionTime: 2.0))
}
This does not work. The agent is running at max speed towards the seek target, ignoring obstacles.
init(targetSpeed: Float, seek: GKAgent, avoid: [GKAgent], obstacles: [GKObstacle]) {
super.init()
setWeight(1.0, for: GKGoal(toAvoid: obstacles, maxPredictionTime: 2.0))
setWeight(0.5, for: GKGoal(toSeekAgent: seek))
setWeight(1.0, for: GKGoal(toReachTargetSpeed: targetSpeed))
setWeight(0.5, for: GKGoal(toAvoid: avoid, maxPredictionTime: 2.0))
}
An interesting detail is that toSeekAgent and toInterceptAgent are actually coloured differently in Xcode than all the other goals. There is nothing in the documentation about this or them overruling other goals.
I have tried to increase the weight for the other goals (like 10000 to 1) but still no success. I have also tried to experiment with the prediction time and the order of the goals.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
