Discuss Scratch

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.
Loopsy54
Scratcher
19 posts

Distance to X,Y

Thank you!
Loopsy54
Scratcher
19 posts

Distance to X,Y

what does ^ mean?
medians
Scratcher
1000+ posts

Distance to X,Y

Loopsy54 wrote:

what does ^ mean?
Exponents (repeated multiplication)
Loopsy54
Scratcher
19 posts

Distance to X,Y

okay
PhiPhenomenon
Scratcher
500+ posts

Distance to X,Y

Loopsy54 wrote:

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

Loopsy54 wrote:

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)

Powered by DjangoBB