Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Check distance between two objects

#1
// 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) {
        
    }
}
1 Like
#2

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
:fox_face::fox_face::fox_face:

1 Like
#3

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

1 Like