Wednesday, January 25, 2017

Steering Behaviors

hey all,

I've been working on getting my steering behaviors working a bit better for most of this week, and I think I'm finally getting close.



The diagram above is based on Mat Buckland's diagrams and description of the wander algorithm that Craig Reynolds developed. Basically, you pick a random point on the red circle, then add a small random displacement to it. You then normalize this displacement to put it back on the red circle. Finally, you project this circle in front of the agent. The vector from the agent to the green circle gives your agent a goal to move towards.

Another way to do it would be to pick a random angle within a limit of your agent's current value, and move your agent towards that angle at a constant speed.

I've developed on that uses 1D Perlin noise to smoothly move from one angle to another.
Vector2 Wander()
 {
  if (currentLoc >= width)
  {
   currentLoc = 0;
   perlinNoise = GenerateNoiseMap(width, seed++, scale, octaves, persistance, lacunarity);
  }

  //get the next angle and increment currentLoc
  WanderAngle = perlinNoise[currentLoc];
  currentLoc++;

  targetRotation = new Vector3(0f, WanderAngle, 0f);
  Vector3 localwanderTarget = new Vector3(Mathf.Cos(WanderAngle * Mathf.Deg2Rad), 0f, Mathf.Sin(WanderAngle * Mathf.Deg2Rad));
  Vector3 worldwanderTarget = transform.TransformDirection(localwanderTarget);

  wanderTarget = new Vector2(worldwanderTarget.x, worldwanderTarget.z);

  return wanderTarget;
 }

Here's a short video showing it at work.



Cheers,

No comments:

Post a Comment