# Enemy distance

**URL:** <https://forum.kirupa.com/t/enemy-distance/244688>\
**Category:** programming\
**Created:** [November 20, 2007, 10:30pm UTC](https://forum.kirupa.com/t/enemy-distance/244688 "2007-11-20T22:30:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr\_beef](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Mr\_beef](https://forum.kirupa.com/u/Mr_beef)\
**Post date:** [November 20, 2007, 10:30pm UTC](https://forum.kirupa.com/t/enemy-distance/244688/1 "2007-11-20T22:30:11Z")

</div>

How can I check to see if the distance between the 2 objects Bandit and Character is less than 20 and if it is then activate the function banditAgressive ();.

So far I’ve tried subtracting the \_root.names.\_x etc from each other and used the

```php
if(playerDistX <20 or playerDistY <20){
banditAgressive ();
}

```

Doesnt work. I havent used distances before so can anyone guide me on a decent way to do this?
