GKGoal toAvoid被忽略

时间:2019-06-15 05:59:34

标签: swift gamekit

您好,谢谢您抽出宝贵的时间来帮助您。

我正在尝试GKGoals,除了toAvoid之外,我已经能够理解并使它们全部工作。

在下面的代码中,toSeek可以正常工作,但是toAvoid被完全寻求忽略/否定了-“玩家”只是在障碍中穿行。即使我已对toAvoid进行了权衡。

我在做什么错,或者我不明白什么。非常感谢

EXTRACT
let obstacles = [GKCircleObstacle(radius: 100), GKCircleObstacle(radius: 100), GKCircleObstacle(radius: 100), GKCircleObstacle(radius: 100)]
obstacles[0].position = vector_float2(200, 500)
obstacles[1].position = vector_float2(250, 500)
obstacles[2].position = vector_float2(300, 500)
obstacles[3].position = vector_float2(20, 500)



EXTRACT
override func touchesBegan(_ touches: Set<UITouch>, 
with event: UIEvent?) {
for t in touches {
loc = t.location(in: self)
print("touchesBegan \(loc)")
}

let targetMove = float2(loc!)
let newTarget = GKAgent2D()
newTarget.position = targetMove

let mmg: [MoveC] = 
entityManager.moveComponentsForTeam(.team1)
let goal1 = GKGoal(toSeekAgent: newTarget)
let goal2 = GKGoal(toAvoid: obstacles, maxPredictionTime: 2)
mmg[0].behavior?.setWeight(10, for: goal1)
mmg[0].behavior?.setWeight(1000, for: goal2)
mmg[0].behavior = GKBehavior(goals: [goal1,goal2])

}

0 个答案:

没有答案