Jump to content
  • Advertisement
Sign in to follow this  

Bots appearing algorithm

This topic is 2842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all!

I need real algorithm of bot's appearing & moving.

Bots (there're car bots), must appear and move around the player in some circle. In whole world there're routes for bot moving. If bot move out circle it must dissapear.

Any ideas, links..

Share this post

Link to post
Share on other sites
I think I know what he wants: something like in the GTA games where there is the illusion of random cars driving all over the city. Actually, only the cars within a certain radius of the player exists. My 'pet' project game is an asteroids clone in open space, and required the same illusion. Basically there's a few parameters, and a few rules:

(For me the 'object' is an asteroid. For you its cars.)


object space radius : maximum distance from player to track these objects
minimum object count : minimum number of objects to have within the object space radius
maximum object count : most number of objects to have within the object space radius


Initial state: When the game starts, for some random number R between minimum and maximum object count, place R objects in random locations within the object space radius. Each object is moving in a random direction. In free space, this was easy, for you, you'll have to restrict each car to a particular road and have it moving in a random direction along that road.

Object leave rule: When updating an object's position, if it falls outside of the object space radius, delete it. If this results in object count going below the minimum, immediately execute the object create rule.

Object create rule: Every so often (random timer, etc) if the number of objects within the object space radius is less than the maximum, create an object on a random point along the object space radius circle (for me in space it was a sphere).

A few notes:

-If you literally implement the Object leave rule, the player could be looking at an object while moving away from it backwards. When the object pops out of existance, if the player move towards where it was, its gone. Instead, have a Object render distance that is somewhat smaller then the object space radius. That way if an object disappears to the player for a moment, it might still exist when he goes back towards it.

- If the player is not moving (or is a moving significantly slower than these objects are), then when creating an object, its best to create one that is moving towards the player. This is because any object moving away from the player will leave the radius in the next frame. (When the player is moving faster than the average speed of these objects, its best to create a mix of objects moving towards and away from the player, because the player can easily overtake the newly created objects and keep them in the radius)

Hope this helps!

Oh, and please let the random cars occasionally crash into each other! I want angry road-raged drivers in your virtual city :) The NPC drivers in Vice City were too nice to each other.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!