Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Distance to X,Y
- Loopsy54
-
Scratcher
19 posts
Distance to X,Y
I need to find the distance between a sprite and a coordinate, can someone help me?
- medians
-
Scratcher
1000+ posts
Distance to X,Y
Use the distance formula:
sqrt((x1 - x2)^2 - (y1 - y2)^2)
And convert it into scratchblocks.
(x1, y1) is the coordinate of the first point, while (x2, y2) is the coordinate of the second point.
sqrt((x1 - x2)^2 - (y1 - y2)^2)
And convert it into scratchblocks.
(x1, y1) is the coordinate of the first point, while (x2, y2) is the coordinate of the second point.
- PhiPhenomenon
-
Scratcher
500+ posts
Distance to X,Y
what does ^ mean?^ means power of, which is the number of times something mutliplies itself by.
So the script medians posted would look like this:
([sqrt v] of ((((x1) - (x2)) * ((x1) - (x2))) + (((y1) - (y2)) * ((y1) - (y2)))))
Last edited by PhiPhenomenon (Feb. 7, 2023 14:23:37)
- Loopsy54
-
Scratcher
19 posts
Distance to X,Y
when they get too far away, it returns with NaN, what do i do?
- medians
-
Scratcher
1000+ posts
Distance to X,Y
when they get too far away, it returns with NaN, what do i do?Oh sorry it should be + not - LOL, and it might be reaching negative square roots because of that
Last edited by medians (Feb. 7, 2023 14:21:40)
- Discussion Forums
- » Help with Scripts
-
» Distance to X,Y


