How do I use the distance expression?

0 favourites
  • 1 posts
From the Asset Store
Add this awesome sound effects to make your visual novel come to life!
  • 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]
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)