[r163] Expression distance wrong

0 favourites
  • 3 posts
From the Asset Store
Be quick and choose whether the shown equation is right or wrong.
  • Problem Description

    Unless the distance expression shouldn't give back the distance between two points, I think this expressions result ist wrong.

    round(distance(Pos1.X, Pos2.X, Pos1.Y,Pos2.Y))[/code:1y391j78]
    
    [u]compared to[/u]
    
    [code:1y391j78]round(sqrt(abs(Pos1.X - Pos2.X)^2 + abs(Pos1.Y - Pos2.Y)^2))[/code:1y391j78]
    
    This - IMHO correct way to calculate the distance - gives a very different result using the distance expression.
      
    [b]Operating System and Service Pack[/b]
    Win7 SVP3
        
    [b]Construct 2 Version ID[/b]
    163
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Not a bug.

    The correct way to use the distance function is:

    distance(Pos1.X, Pos1.Y, Pos2.X, Pos2.Y)[/code:1czenn2n]
    Notice the x,y pairs are next to each other.
    
    It's exactly the same as:
    [code:1czenn2n]sqrt((Pos2.X - Pos1.X)^2 + (Pos2.Y - Pos1.Y)^2)[/code:1czenn2n]
    or
    [code:1czenn2n]sqrt((Pos1.X - Pos2.X)^2 + (Pos1.Y - Pos2.Y)^2)[/code:1czenn2n]
    
    The abs() isn't needed since any number squared is always positive.
  • Ahh, my bad, sorry, sorry, sorry -> ashamed in the leftmost corner.... (the eyes, old eyes, small screen, high resolution )

    Thanks R0J0hound. I'll try to delete or let this thread delete.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)