# distanceTo bug from object other than the player

**URL:** <https://discourse.codecombat.com/t/distanceto-bug-from-object-other-than-the-player/2139>\
**Category:** Bugs\
**Created:** [December 31, 2014, 3:32am UTC](https://discourse.codecombat.com/t/distanceto-bug-from-object-other-than-the-player/2139 "2014-12-31T03:32:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sotonin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sotonin/32/24089_2.png) [@sotonin](https://discourse.codecombat.com/u/sotonin)\
**Post date:** [December 31, 2014, 3:32am UTC](https://discourse.codecombat.com/t/distanceto-bug-from-object-other-than-the-player/2139/1 "2014-12-31T03:32:26Z")

</div>

It seems we can not access the method distanceTo from an enemy object. It doesn’t matter what you pass into distanceTo, an item object or an object with x and y coords on it. it says this.

**Calling distanceTo is not allowed.**

```python
var enemy = this.findNearest(this.findEnemies());
if (enemy) {
    this.say(enemy.distanceTo({x: 5, y: 5}));
}

```

I need this functionality to determine if the enemy hero is nearby the next coordinate i wish to move to. (to direct my player to move the other direction instead)

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [December 31, 2014, 4:46am UTC](https://discourse.codecombat.com/t/distanceto-bug-from-object-other-than-the-player/2139/2 "2014-12-31T04:46:15Z")

</div>

Are you sure that you have an item with distanceTo?

---

<div class="post-metadata">

**Author:** ![sotonin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/sotonin/32/24089_2.png) [@sotonin](https://discourse.codecombat.com/u/sotonin)\
**Post date:** [December 31, 2014, 4:48am UTC](https://discourse.codecombat.com/t/distanceto-bug-from-object-other-than-the-player/2139/3 "2014-12-31T04:48:30Z")

</div>

That’s what i’m requesting, if it’s not there or restricted for it to be opened up / implemented. 🙂

But if it weren’t there it would say undefined function. It says is not allowed.

---

<div class="post-metadata">

**Author:** ![Feinty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/feinty/32/1869_2.png) [@Feinty](https://discourse.codecombat.com/u/Feinty)\
**Post date:** [December 31, 2014, 4:56am UTC](https://discourse.codecombat.com/t/distanceto-bug-from-object-other-than-the-player/2139/4 "2014-12-31T04:56:15Z")

</div>

just checked this it works fine for me are you on a certain level?

---

<div class="post-metadata">

**Author:** ![nick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nick/32/784_2.png) [@nick](https://discourse.codecombat.com/u/nick)\
**Post date:** [December 31, 2014, 7:31pm UTC](https://discourse.codecombat.com/t/distanceto-bug-from-object-other-than-the-player/2139/5 "2014-12-31T19:31:18Z")

</div>

How about now? It looks like the default API properties were `distance` and `getNearest` (the old names) instead of `distanceTo` and `findNearest`.
