Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
0
Members

How to get Distance between Actors? [Solved]

A topic by iWriteTheCode created Jun 14, 2016 Views: 804 Replies: 4
Viewing posts 1 to 3
(+1)

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:

Sup.log(distance);

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

Sup.Math.Vector3.prototype.distanceTo(EnemyPos)

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 ^^

(+1)

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