# Interesting chase/follow command

**URL:** https://forum.kirupa.com/t/interesting-chase-follow-command/248158
**Category:** programming
**Created:** [January 4, 2008, 2:14pm UTC](https://forum.kirupa.com/t/interesting-chase-follow-command/248158 "2008-01-04T14:14:22Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![leejay](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@leejay](https://forum.kirupa.com/u/leejay)
#### Post date: [January 4, 2008, 2:14pm UTC](https://forum.kirupa.com/t/interesting-chase-follow-command/248158/1 "2008-01-04T14:14:22Z")

</div>

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](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
