How do I measure the distance between 2 different parallax points?

0 favourites
  • 5 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • I'm struggling to figure out how to measure the distance in between 2 points (the first on a layer with 100%x100% parallax, the second on a layer with 0%x0% parallax).

    The second point represents the gamepad's crosshair for my game, while the first one represents the gun (for setting the width of lasers, scopes and such).

    Obviously, simply setting the width to distance(point1x,point1y,point2x,point2y) doesn't works

    Already tried several ways, including making a function that returns numbers; with equations including scrollx and scrolly (and dividing both positions by the viewport's height/width) - came kinda close to it, but couldn't find why it doesn't works sometimes.

    Help would be greatly appreciated

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • My current workaround is to keep increasing the line's width until it overlaps the crosshair. But it's not quite as fast nor performance friendly as it could be.

  • You can convert coordinates from layer B to A using these monstrous expressions:

    CanvasToLayerX("A", LayerToCanvasX("B", x, y), LayerToCanvasY("B", x, y))

    CanvasToLayerY("A", LayerToCanvasX("B", x, y), LayerToCanvasY("B", x, y))

  • Hmmm interesting, never thought of using it that way.

    Thanks, gonna try it out later

  • Update: Oh my god, that's it, it worked

    Thanks a lot lol, couldn't find this anywhere else.

    When my game launches, I'll give it to you for free if you want it; cause srsly, lost almost a whole week of progress to this issue.

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