Discuss Scratch

Jareddddddd
Scratcher
1000+ posts

fastest way to find distance

I need the fastest way to find the distance between to sprites, not using X and Y coords.
For reference, this is a raycaster, so it shoots rays out and records how long it takes to hit something. I would like the absolute fastest way you can do this
My current code (for finding distance)
repeatuntil179<castortouchingmap wall?move1stepschangecastby1
crazyy_coder
Scratcher
8 posts

fastest way to find distance

Konserverad_gran
Scratcher
77 posts

fastest way to find distance

Also, if you haven't already done so, remember putting the code under a custom block and toggling “run without screen refresh” on. This makes it faster.
Burnt-Butter-Toast
Scratcher
78 posts

fastest way to find distance

Jareddddddd wrote:

I need the fastest way to find the distance between two sprites, not using X and Y cords.
For reference, this is a raycaster, so it shoots rays out and records how long it takes to hit something. I would like the absolute fastest way you can do this
My current code (for finding distance)
repeatuntil179<castortouchingmap wall?move1stepschangecastby1
Well, you could use the Pythagorean Theorem, a^2 + b^2 = c^2.
Makes the slope into a right triangle where the vertical line is a leg (a or b) and the flat line is also a leg (also a or b)
Be sure the x
setatosetctox^2ofa+x^2ofbmovesqrtofcsteps

OK ignore ALL of that, while trying to find what I was trying to say I say a “distance to mouse pointer” but you can change it to a sprite and use that value

Powered by DjangoBB