PDA

View Full Version : Interesting chase/follow command



leejay
January 4th, 2008, 10:14 AM
Hey there,

I am in the process of creating a kind of cat and mouse style game but the player controls a car and a police car chases and you are timed to see how long you last before your car loses its life from too many collisions...

I found an awesome site http://www.sploder.com/free-game-creator.php that lets you create your own game. Within this, There are wingman that follow you around but don't get stuck and have a bit more intelligence than my police car! I have already written some code but I am having some trouble with the police car as it keeps getting stuck behind buildings. Could you tell me where i am going wrong? Or point me in the direction of a decent tutorial?

At the moment I've been working with this for the police car:

if (this._x<_root.player._x or this._x<_root.player._x+1) {
this._x += 2;
} else {
this._x -= 2;
}
if (this._y<_root.player._y or this._y<_root.player._y+1) {
this._y += 2;
} else {
this._y -= 2;
}

Thank you for you time and help

ArmoredSandwich
January 4th, 2008, 11:50 AM
pathfinding is one of the most difficult things of artificial intelligence. Youre looking for something called A* pathfinding. http://www.policyalmanac.org/games/aStarTutorial.htm

It is extremely hard to program. I suggest you do something more easier, for example have the police cars patrol and only chase you if the distance is smaller then a certain number.

that way theyll lose you too.

fw2803
January 7th, 2008, 07:01 AM
Easier stuff. Police helicopter instead of a police car... Then you can use some homing codes to do the job.

Homing stuff has been discussed earlier in a Firing, Homing, Hitting... thread (if I remember the name correctly) that I started.

DangerousDan
January 11th, 2008, 11:37 AM
An alternative method would be to save your player's position everytime they move in an array and then have the police car follow it by going through the array.

More or less a messy work-a-round. :p: