Making dot move around

BlitzMax Forums/BlitzMax Programming/Making dot move around

MattVonFat(Posted 2005) [#1]
Hi. I am trying to make an ant that will pile up items. I first need him to walk around. I've tried generating a random number between -1 and 1 so that he moves in different directions but of course this just leaves me with an ant that looks as though hes having muscle spasms.

Any ideas how i would get him to randomly walk around the screen?


Robert(Posted 2005) [#2]
You need to establish an amount of time between each decision about direction the ant makes.

So when the ant first starts, he would consider a direction and a time for which to travel that far. When that time has elapsed or if the ant reaches the edge of the screen, the direction and distance should be reconsidered. In order to ensure that the 'muscle spasm' problem doesn't happen, put a lower limit on the possible time between decision making (say min time: one second, max time: five seconds)

Edit: As a second thought, you would probably want to make sure that each 'new' direction was neither too close nor too far from the original direction. Otherwise the ant may appear to jerk, or will do stupid things like suddenly doing an about-turn.


MattVonFat(Posted 2005) [#3]
Ok thanks, thats a great help.


xlsior(Posted 2005) [#4]
check out this link for some theories this kind of thing:

http://www.red3d.com/cwr/steer/

It has some java examples that you can view in your browser, and some explanations on how they work. You'll probably want the 'wander' algorithm.

Basically it puts an imaginary full circle in front of your 'ant', and pick a random spot on the circumference of this circle.

You steer your ant in a straight line towards this spot.
However, each step the ant takes, the circle moves one step away as well in the same direction (so it always stays ahead of you), and your selected spot will randomly move either left or right a step, following the circumference of the circle.

This acts as a directional vector: you keep aiming your ant in a direct line towards this spopt on the edge of the circle.

Because of the shape of the arch projected in front of you, you essentially 'dampen' then randomness, movements gets smoothed out over time. The wandering will appear much more natural and less epileptic than a pure 'turn left, turn right, turn right, etc.)

The size of the circle will affect how jittery the movement will be: a small circle will lead to more erratic wandering, while a huge circle will not deviate much from its cource. Pick a size that suit your needs.

(A full circle will cause your ant to wander all over, you can make it more restrictive by using a partial arch instead of the entire circle.)

Anyway, it's a bit hard to describe -- follow the link for a visual example.