I need to restrain my agents from going off the screen. I tried the following:
let screenWidth = UIScreen.mainScreen().bounds.width
let screenHeight = UIScreen.mainScreen().bounds.height
// bottom
let obstacle1 = GKPolygonObstacle(points: UnsafeMutablePointer([float2(0, 0), float2(Float(screenWidth), 0)]), count: 2)
// left
let obstacle2 = GKPolygonObstacle(points: UnsafeMutablePointer([float2(0, 0), float2(0, Float(screenHeight))]), count: 2)
// right
let obstacle3 = GKPolygonObstacle(points: UnsafeMutablePointer([float2(Float(screenWidth), 0), float2(Float(screenWidth), Float(screenHeight))]), count: 2)
// top
let obstacle4 = GKPolygonObstacle(points: UnsafeMutablePointer([float2(0, Float(screenHeight)), float2(Float(screenWidth), Float(screenHeight))]), count: 2)
let obstacles = [obstacle1, obstacle2, obstacle3, obstacle4]
// set the goal for the behaviour of the agent
agent.behavior?.setWeight(1000000, forGoal: GKGoal(toAvoidObstacles: obstacles, maxPredictionTime: 1))
This, however, does not work. The agent has other working goals so it is set up properly. What am I doing wrong?