How do I use the distance expression?

Get help using Construct 2

Post » Tue May 10, 2016 11:32 am

Edit 2: Solved. The text box was too small to display the result for the diagonal values, as these had more digits than could be displayed in the size of the box.

I'm trying to find the distance between two pathfinding nodes. I use the expression
Code: Select all
distance(distance(Sprite.Pathfinding.NodeXAt(loopindex), Sprite.Pathfinding.NodeYAt(loopindex), Sprite.Pathfinding.NodeXAt(loopindex - 1), Sprite.Pathfinding.NodeYAt(loopindex - 1))
in the tutorial as an example, which produces this result: Image
As you can see, the nodes which are horizontal and vertical from each other show the distance, however those that aren't don't. I tried using this just to test it out
Code: Select all
distance(0,0,100,100)
which doesn't work and
Code: Select all
distance(0,0,0,100)
which does.

Is this a limitation of the expression or am I doing it wrong? I could calculate it myself but this seems quicker.

Thanks :)

Edit: the same thing happens when I try to calculate it, using the expression
Code: Select all
sqrt((sprite.Pathfinding.NodeXAt(loopindex - 1) - sprite.Pathfinding.NodeXAt(loopindex)) ^ 2 + (sprite.Pathfinding.NodeYAt(loopindex - 1) - sprite.Pathfinding.NodeYAt(loopindex )) ^ 2)

- which works when I calculate it myself with given x and y coordinates, so i'm sure i'm doing something wrong here.
B
9
S
1
Posts: 12
Reputation: 448

Return to How do I....?

Who is online

Users browsing this forum: bluesun66, jasontoups and 1 guest