4 Replies
      Latest reply on Aug 20, 2018 4:39 AM by funkytomato
      shalevy Level 1 Level 1 (0 points)

        I build a very simple example in playground to start understanding Agent/Behavior/Goals. I was able to add a goal for toReachTargetSpeed, but my second test was to add a wander goal. I thought I understood the speed parameter but it just seems to produce very little wander movement. Here is the example I use:

        import GameplayKit

        @available(iOS 9.0, *)

        func testAgent() {

            let agent = GKAgent2D()

            agent.mass = 2

            agent.maxAcceleration = 90

            agent.maxSpeed = 120

            agent.radius = 5

            agent.position = float2(x:0,y:0)

            agent.rotation = 0


            agent.behavior = GKBehavior(goal: GKGoal(toReachTargetSpeed: 110), weight: 1)

            agent.behavior!.setWeight(5.0, forGoal: GKGoal(toWander: 90))


            for _ in (0..<80) {






        if #available(iOS 9, *) {




        The results are: (just the last 2)


        float2(246.718, 4.70492e-18)


        float2(251.523, -2.50744e-18)



        So Wander does add a small change in the Y position, but very tiny. Any idea where I'm wrong?




        • Re: Anyone able to get the toWander goal to work?
          Fuzzygoat Level 1 Level 1 (20 points)

          Having the same problem with wander, it might be broken.




          • Re: Anyone able to get the toWander goal to work?
            Fuzzygoat Level 1 Level 1 (20 points)

            I have managed to get the wander goal to work at last, these are the settings I used. Also make sure that you are correctly updating both position and rotation in the GKAgentDelegate callbacks.


                func setupWanderBehavior() {
                    let seekGoal = GKGoal(toSeekAgent: self.seekAgent)
                    let wanderGoal = GKGoal(toWander: 1.0)
                    let behavior = GKBehavior(goals: [seekGoal, wanderGoal], andWeights: [0.1, 50.0])
                    for eachCritter in self.flock {
                        eachCritter.behavior = behavior


            The critters are wandering randomly with a very weak goal to seek the center cross-hair in the center of the image. The goal weight for wander does seem to need to be very large, small values showed no change in the y-axis which is what I was seeing before. I tested wander without the seek goal and the results are as expected, seek just helps persuade the critters to stay on-screen.


            Sample image: https://goo.gl/photos/6Na9GnGsb4LpELeK7



            • Re: Anyone able to get the toWander goal to work?
              karim Level 1 Level 1 (0 points)

              I realize this is an old post, but is anyone else still having issues with the wander goal in 9.2 beta? The behavior I see is that the node rotation gets updated, but the position isn't updated in either x or y, so the node just spins randomly. I've played with all the agent settings, but without much success.