-3
\$\begingroup\$

So I'm creating a zombie game where the zombies are passive and just walk randomly all over the area when player is not near. My question is: how would I make zombies move randomly? I code in C#. Basically, there is a town filled with zombies that just wander around the area (walk randomly everywhere slowly) until the player is seen or is very near. Thanks.

\$\endgroup\$
5

2 Answers 2

3
\$\begingroup\$

You would need to implement two AI states: Seek & Wander The zombies will have to have an attention radius.

if player is within the attention radius
    seek(player)
else
    wander()

In each wander behaviour you will want to have a location for it to wander to. If you have a complex area you would want to have the zombie follow a specified path. Which I would suggest to use A* to create the paths.

function wander()
    if path is empty
        findPath(randomPoint)
    else
        seek(path.NextNode.position)

To be able to steer towards a point you want to use the dot product. Here is what I use to steer towards a point:

function seek(point)
    fwd = normalize(getForwardVector())
    diff = normalize(point - this.position)
    dot = dot(fwd, diff)
    this.rotationalVelocity.y = dot * this.rotationalSpeed;
    this.velocity = fwd * this.wanderSpeed;

If you want to make the zombies even more dumb you could test if the dot product of the fwd, and diff vectors are greater than 0. That means the zombie is facing the player. If it less than or equal to 0 then don't seek the player.

\$\endgroup\$
1
\$\begingroup\$

For random movement, define variable radius, which is the greatest distance that the zombie can go at a moment, and some sort of time variable which is how long they will stand there. Generate a vector with distance less than radius, and angle of which you want the zombie to move. Then, wait a random amount of time, and repeat. Of course, this is a very simple and "stupid" ai. Like mentioned above, A* would probably be the way to go with randomly generated obstacles to make paths.

Good luck

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .