0 Replies
      Latest reply on Jun 16, 2019 10:51 AM by simonj.se6@gmail.com
      simonj.se6@gmail.com Level 1 Level 1 (0 points)

        Hello and thank you for taking the time to help.

        I am experimenting with GKGoals and have been able to understand and make them all work except for toAvoid.


        In the code below the toSeek is working fine, but the toAvoid is ignored / overruled by the to seek completely - the 'player' just walking right through the obstacles. Even though I have weighted the toAvoid strongly.

        What am I doing wrong, or what do I not understand please.



        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)
        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] =
        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])



        Just a thought, in the above I have created an array of obstacles, and then set their position. Is that all? Do I need to ADD them - I have read the documentation and cannot see that I do.


        Many thanks for your time, and apologies upfront if I am making foolish mistakes