Anyone able to get the toWander goal to work?

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) {

agent.updateWithDeltaTime(0.05)

print(agent.position)

print(agent.speed)

}

}

if #available(iOS 9, *) {

testAgent()

}


The results are: (just the last 2)


float2(246.718, 4.70492e-18)

95.7104

float2(251.523, -2.50744e-18)

96.0825


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


Thanks,

Shay

Replies

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

https://forums.developer.apple.com/message/17148#17148


Gary.

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



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.

I have found that including a SeekGoal behaviour with a wander behaviour seems to resolve the issue of entities becoming stuck in corners, 90% of the time... 😟


I don't seem to be able to stop entities from walking straight into walls, or sliding along them though...