Discuss Scratch
- UndeadSorcerer
-
100+ posts
Distance to (x) (y)
For my tower defense game I think this will help. It might be useful for other things too!
Tell me if you support!
Also if there is any way to get around this please tell me.
(distance to x:() y:()::sensing)
Tell me if you support!
Also if there is any way to get around this please tell me.
- stickfiregames
-
1000+ posts
Distance to (x) (y)
Support, the workaround is very long:
([sqrt v] of ((((x :: grey) - (x position)) * ((x :: grey) - (x position))) + (((y :: grey) - (y position)) * ((y :: grey) - (y position))))
- zacadoole1
-
100+ posts
Distance to (x) (y)
Support, but for an alternate workaround couldn't you just have a hidden sprite at the location you want to find the distance from, then use the "distance to " block? Support, the workaround is very long:([sqrt v] of ((((x :: grey) - (x position)) * ((x :: grey) - (x position))) + (((y :: grey) - (y position)) * ((y :: grey) - (y position))))
Last edited by zacadoole1 (April 23, 2015 18:46:24)
- stickfiregames
-
1000+ posts
Distance to (x) (y)
You could, but then of course you need another sprite and have to use broadcasts.Support, but for an alternate workaround couldn't you just have a hidden sprite at the location you want to find the distance from, then use the "distance to " block? Support, the workaround is very long:([sqrt v] of ((((x :: grey) - (x position)) * ((x :: grey) - (x position))) + (((y :: grey) - (y position)) * ((y :: grey) - (y position))))
- zacadoole1
-
100+ posts
Distance to (x) (y)
Yeah, but it's easier for me to remember than all those math blocks!You could, but then of course you need another sprite and have to use broadcasts.Support, but for an alternate workaround couldn't you just have a hidden sprite at the location you want to find the distance from, then use the "distance to " block? Support, the workaround is very long:([sqrt v] of ((((x :: grey) - (x position)) * ((x :: grey) - (x position))) + (((y :: grey) - (y position)) * ((y :: grey) - (y position))))

- Prinseskat
-
1000+ posts
Distance to (x) (y)
Easy to remember if you know how it works.Yeah, but it's easier for me to remember than all those math blocks!You could, but then of course you need another sprite and have to use broadcasts.Support, but for an alternate workaround couldn't you just have a hidden sprite at the location you want to find the distance from, then use the "distance to " block? Support, the workaround is very long:([sqrt v] of ((((x :: grey) - (x position)) * ((x :: grey) - (x position))) + (((y :: grey) - (y position)) * ((y :: grey) - (y position))))
lol the block's going out of the quote section
Last edited by Prinseskat (April 23, 2015 19:10:23)
- zacadoole1
-
100+ posts
Distance to (x) (y)
Oh, I could probably memorize it if I really wanted to, but you know what they say, you can't teach an old dog new tricks!Easy to remember if you know how it works.Yeah, but it's easier for me to remember than all those math blocks!You could, but then of course you need another sprite and have to use broadcasts.Support, but for an alternate workaround couldn't you just have a hidden sprite at the location you want to find the distance from, then use the "distance to " block? Support, the workaround is very long:([sqrt v] of ((((x :: grey) - (x position)) * ((x :: grey) - (x position))) + (((y :: grey) - (y position)) * ((y :: grey) - (y position))))

- stickfiregames
-
1000+ posts
Distance to (x) (y)
It would be easier if we had a power block too:Oh, I could probably memorize it if I really wanted to, but you know what they say, you can't teach an old dog new tricks!Easy to remember if you know how it works.Yeah, but it's easier for me to remember than all those math blocks!You could, but then of course you need another sprite and have to use broadcasts.Support, but for an alternate workaround couldn't you just have a hidden sprite at the location you want to find the distance from, then use the "distance to " block? Support, the workaround is very long:([sqrt v] of ((((x :: grey) - (x position)) * ((x :: grey) - (x position))) + (((y :: grey) - (y position)) * ((y :: grey) - (y position))))
([sqrt v] of ((((x :: grey) - (x position)) ^ (2) :: operators) + (((y :: grey) - (y position)) ^ (2) :: operators))Still long though.
- Seapats
-
70 posts
Distance to (x) (y)
Support, the workaround is very long:([sqrt v] of ((((x :: grey) - (x position)) * ((x :: grey) - (x position))) + (((y :: grey) - (y position)) * ((y :: grey) - (y position))))
Yes I used this for a project this would really help!
- MegaApuTurkUltra
-
1000+ posts
Distance to (x) (y)
Support. This would help new scratchers who don't want to use the “complicated” workaround.
- Dobbatron
-
3 posts
Distance to (x) (y)
This needs the formula:
SQRT of Xposition of one sprite - X position of other sprite * Xposition of one sprite - X position of other sprite + yposition of one sprite - y position of other sprite * yposition of one sprite - y position of other sprite
Hope this helped!
SQRT of Xposition of one sprite - X position of other sprite * Xposition of one sprite - X position of other sprite + yposition of one sprite - y position of other sprite * yposition of one sprite - y position of other sprite

Last edited by Dobbatron (Oct. 23, 2017 18:06:48)
- Cub56
-
1000+ posts
Distance to (x) (y)
I won't support because this workaround is what's used in many other programming languages and it'd probably be a good thing for new Scratchers to learn the maths behind it.
- Sigton
-
1000+ posts
Distance to (x) (y)
define distance to (x) (y)
set [dx v] to ((x) - (x position))
set [dy v] to ((y) - (y position))
set [distance v] to ([sqrt v] of (((dx) * (dx)) + ((dy) * (dy))))
A nice and neat custom block for you

Sigton
- Charles12310
-
1000+ posts
Distance to (x) (y)
So, how do they even know if that script is gonna work? They don't understand how it works, why should we be expecting users to solve complicated problems and they aren't even in high school? I won't support because this workaround is what's used in many other programming languages and it'd probably be a good thing for new Scratchers to learn the maths behind it.
- walkcycle
-
500+ posts
Distance to (x) (y)
I won't support because this workaround is what's used in many other programming languages and it'd probably be a good thing for new Scratchers to learn the maths behind it.
I agree, it is a great opportunity to learn the math of distance.
That's excellent.define distance to (x) (y)
set [dx v] to ((x) - (x position))
set [dy v] to ((y) - (y position))
set [distance v] to ([sqrt v] of (((dx) * (dx)) + ((dy) * (dy))))
A nice and neat custom block for you
Sigton
Another work round
go to x: () y: () // sprite1
(distance to [sprite1 v]) // sprite2
So, how do they even know if that script is gonna work?
By testing.
- Charles12310
-
1000+ posts
Distance to (x) (y)
Yes but that's like saying the workaround is easy. -_-I won't support because this workaround is what's used in many other programming languages and it'd probably be a good thing for new Scratchers to learn the maths behind it.
I agree, it is a great opportunity to learn the math of distance.That's excellent.define distance to (x) (y)
set [dx v] to ((x) - (x position))
set [dy v] to ((y) - (y position))
set [distance v] to ([sqrt v] of (((dx) * (dx)) + ((dy) * (dy))))
A nice and neat custom block for you
Sigton
Another work roundgo to x: () y: () // sprite1
(distance to [sprite1 v]) // sprite2So, how do they even know if that script is gonna work?
By testing.
The workaround is difficult, not everyone knows how it works, and I don't think everyone's gonna remember. I know about square roots but I can't even remember either. It's better to drag one block than to drag so many blocks and type so many stuff and then you realized that you forgot everything.
- Cub56
-
1000+ posts
Distance to (x) (y)
It is only Pythagoras and I learnt it practically at the start of the equivalent of middle school.So, how do they even know if that script is gonna work? They don't understand how it works, why should we be expecting users to solve complicated problems and they aren't even in high school? I won't support because this workaround is what's used in many other programming languages and it'd probably be a good thing for new Scratchers to learn the maths behind it.
- Charles12310
-
1000+ posts
Distance to (x) (y)
Yes, but still you don't understand, the workaround is too long, it takes too much dragging of blocks, it's better to use one block alone. Most people probably aren't in middle school yet!