0 Favourites

# How do I use the distance expression?

• 1 posts
• 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

``````distance(distance(Sprite.Pathfinding.NodeXAt(loopindex), Sprite.Pathfinding.NodeYAt(loopindex), Sprite.Pathfinding.NodeXAt(loopindex - 1), Sprite.Pathfinding.NodeYAt(loopindex - 1))[/code:2a4cmomz] in the tutorial as an example, which produces this result: [img="http://i.imgur.com/GlatZSf.png"]
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:2a4cmomz]distance(0,0,100,100)[/code:2a4cmomz] which doesn't work and [code:2a4cmomz]distance(0,0,0,100)[/code:2a4cmomz] 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:2a4cmomz]sqrt((sprite.Pathfinding.NodeXAt(loopindex - 1) - sprite.Pathfinding.NodeXAt(loopindex)) ^ 2 + (sprite.Pathfinding.NodeYAt(loopindex - 1) - sprite.Pathfinding.NodeYAt(loopindex )) ^ 2)[/code:2a4cmomz]
[ul]
[li]which works when I calculate it myself with given x and y coordinates, so i'm sure i'm doing something wrong here.[/li]
[/ul]``````