# Check distance between two objects

**URL:** <https://discourse.codecombat.com/t/check-distance-between-two-objects/17843>\
**Category:** Artisan\
**Created:** [March 15, 2019, 2:58pm UTC](https://discourse.codecombat.com/t/check-distance-between-two-objects/17843 "2019-03-15T14:58:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cullen\_Fasick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cullen_fasick/32/9865_2.png) [@Cullen\_Fasick](https://discourse.codecombat.com/u/Cullen_Fasick)\
**Post date:** [March 15, 2019, 2:58pm UTC](https://discourse.codecombat.com/t/check-distance-between-two-objects/17843/1 "2019-03-15T14:58:47Z")

</div>

```python
// How do I check the distance between two objects? And also how do I destroy one of the xmarks thats too close then respawn it? heres my code so far
game.addSurviveGoal();
game.addManualGoal("Answer all the questions right!");
var crossX = game.randomInteger(4, 52);
var crossX2 = game.randomInteger(4, 76);
var crossX3 = game.randomInteger(4, 76);
var player = game.spawnHeroXY(42, 6);
var xmark1 = game.spawnXY("x-mark-bones", crossX, 52);
var xmark2 = game.spawnXY("x-mark-bones", crossX2, 52);
var xmark3 = game.spawnXY("x-mark-bones", crossX3, 52);
function checkDistance() {
    // I need a code here that will check the distance between the x marks so I can make it so they don't spawn too close or on top of each other!
}
function checkProximityCorrect() {
    if(xmark1.distanceTo(player) <= 1) {
        
    }
}
function checkProximityWrong() {
    if(xmark2.distanceTo(player) <= 1) {
        
    }
}

```

---

<div class="post-metadata">

**Author:** ![Luke10](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/luke10/32/19892_2.png) [@Luke10](https://discourse.codecombat.com/u/Luke10)\
**Post date:** [March 15, 2019, 5:08pm UTC](https://discourse.codecombat.com/t/check-distance-between-two-objects/17843/2 "2019-03-15T17:08:55Z")

</div>

Please give further information about your issue. Such as any errors that pop up when you run your code, and what happens when you run your code. A screenshot would also be helpful

-@Luke10  
🦊🦊🦊

---

<div class="post-metadata">

**Author:** ![Cullen\_Fasick](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/cullen_fasick/32/9865_2.png) [@Cullen\_Fasick](https://discourse.codecombat.com/u/Cullen_Fasick)\
**Post date:** [March 15, 2019, 5:12pm UTC](https://discourse.codecombat.com/t/check-distance-between-two-objects/17843/3 "2019-03-15T17:12:04Z")

</div>

> [@Cullen\_Fasick](#):
>
> // How do I check the distance between two objects? And also how do I destroy one of the xmarks thats too close then respawn it? heres my code so far game.addSurviveGoal(); game.addManualGoal(“Answer all the questions right!”); var crossX = game.randomInteger(4, 52); var crossX2 = game.randomInteger(4, 76); var crossX3 = game.randomInteger(4, 76); var player = game.spawnHeroXY(42, 6); var xmark1 = game.spawnXY(“x-mark-bones”, crossX, 52); var xmark2 = game.spawnXY(“x-mark-bones”, crossX2, 52); var xmark3 = game.spawnXY(“x-mark-bones”, crossX3, 52); function checkDistance() { // I need a code here that will check the distance between the x marks so I can make it so they don’t spawn too close or on top of each other! } function checkProximityCorrect() { if(xmark1.distanceTo(player) \<= 1) { } } function checkProximityWrong() { if(xmark2.distanceTo(player) \<= 1) { } }

Like how do I make it so they respawn if they get too close or are not on the right spots?
