🤑 Indie game store🙌 Free games😂 Fun games😨 Horror games
👷 Game development🎨 Assets📚 Comics
🎉 Sales🎁 Bundles

How to get Distance between Actors? [Solved]

A topic by iWriteTheCode created 1 year ago Views: 257 Replies: 4
Viewing posts 1 to 3

So while making a game I was trying to get the distance between the player and an enemy so I did:

let ShipPos = this.actor.getPosition();

let EnemyPos = Sup.getActor("OtherShip").getPosition();

let distance = Sup.Math.Vector3.prototype.distanceTo(EnemyPos)

This all checks out fine I get the blue light to run the game but when I wanted to print out the distance in the debugger I used:


And it didn't work, it just prints out "NaN" I also tried putting the:


Into the log but I got the same result. Any thoughts?

NaN means not a number. So the fact that it prints that means your other ship value may not actually exist. I'm not exactly sure how to fix this.

Make sure you are using the correct naming and spelling.

Try printing the other ships position to the console, it may offer some insight into the issue.

Printing the two different positions works but the distance does not. :(

Hi !

let distance = ShipPos.distanceTo(EnemyPos) should work ^^


Thank you so much! As soon as I saw the solution I knew I should have already tried it xD Thanks again your great!