Discuss Scratch

UndeadSorcerer
Scratcher
100+ posts

Distance to (x) (y)

For my tower defense game I think this will help. It might be useful for other things too!

(distance to x:() y:()::sensing)

Tell me if you support!

Also if there is any way to get around this please tell me.
stickfiregames
Scratcher
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))))










If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
CatsUnited
Scratcher
1000+ posts

Distance to (x) (y)

Support

bottom text
zacadoole1
Scratcher
100+ posts

Distance to (x) (y)

stickfiregames wrote:

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))))
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?

Last edited by zacadoole1 (April 23, 2015 18:46:24)



As of 9/25/16 I run Firefox 47.0.1 (64-bit) with Flash Plugin v23.0 r0 on Windows 10 (Anniversary Update).
Click here to give me an internet! You know, if you want to. No pressure…
Joey James Jr. is my spirit animal. <3
stickfiregames
Scratcher
1000+ posts

Distance to (x) (y)

zacadoole1 wrote:

stickfiregames wrote:

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))))
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?
You could, but then of course you need another sprite and have to use broadcasts.











If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
zacadoole1
Scratcher
100+ posts

Distance to (x) (y)

stickfiregames wrote:

zacadoole1 wrote:

stickfiregames wrote:

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))))
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?
You could, but then of course you need another sprite and have to use broadcasts.

Yeah, but it's easier for me to remember than all those math blocks!


As of 9/25/16 I run Firefox 47.0.1 (64-bit) with Flash Plugin v23.0 r0 on Windows 10 (Anniversary Update).
Click here to give me an internet! You know, if you want to. No pressure…
Joey James Jr. is my spirit animal. <3
Prinseskat
Scratcher
1000+ posts

Distance to (x) (y)

zacadoole1 wrote:

stickfiregames wrote:

zacadoole1 wrote:

stickfiregames wrote:

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))))
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?
You could, but then of course you need another sprite and have to use broadcasts.

Yeah, but it's easier for me to remember than all those math blocks!
Easy to remember if you know how it works.

lol the block's going out of the quote section

Last edited by Prinseskat (April 23, 2015 19:10:23)


haha funny kumquat meme
zacadoole1
Scratcher
100+ posts

Distance to (x) (y)

Prinseskat wrote:

zacadoole1 wrote:

stickfiregames wrote:

zacadoole1 wrote:

stickfiregames wrote:

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))))
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?
You could, but then of course you need another sprite and have to use broadcasts.

Yeah, but it's easier for me to remember than all those math blocks!
Easy to remember if you know how it works.
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!


As of 9/25/16 I run Firefox 47.0.1 (64-bit) with Flash Plugin v23.0 r0 on Windows 10 (Anniversary Update).
Click here to give me an internet! You know, if you want to. No pressure…
Joey James Jr. is my spirit animal. <3
stickfiregames
Scratcher
1000+ posts

Distance to (x) (y)

zacadoole1 wrote:

Prinseskat wrote:

zacadoole1 wrote:

stickfiregames wrote:

zacadoole1 wrote:

stickfiregames wrote:

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))))
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?
You could, but then of course you need another sprite and have to use broadcasts.

Yeah, but it's easier for me to remember than all those math blocks!
Easy to remember if you know how it works.
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!
It would be easier if we had a power block too:
([sqrt v] of ((((x :: grey) - (x position)) ^ (2) :: operators) + (((y :: grey) - (y position)) ^ (2) :: operators))
Still long though.










If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
Seapats
Scratcher
70 posts

Distance to (x) (y)

stickfiregames wrote:

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!

Three things i dislike:
1. Lists
2. Signatures
4. Irony
5. When people say they only are going to say 3 things then say 4.
MegaApuTurkUltra
Scratcher
1000+ posts

Distance to (x) (y)

Support. This would help new scratchers who don't want to use the “complicated” workaround.

$(".box-head")[0].textContent = "committing AT crimes since $whenever"
Dobbatron
Scratcher
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!

Last edited by Dobbatron (Oct. 23, 2017 18:06:48)

Cub56
Scratcher
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.

Check out Life Raft Survival, my new advanced sandbox survival game with crafting, building, transportation, weather events, tropical storms, and more!

In the game you're stranded at sea after a mysterious crash and must survive in an unforgiving tropical island environment collecting resources and crafting, in an attempt to finally be rescued.



Sigton
Scratcher
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
Scratcher
1000+ posts

Distance to (x) (y)

Cub56 wrote:

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.
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?


A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
walkcycle
Scratcher
500+ posts

Distance to (x) (y)

Cub56 wrote:

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.

Sigton wrote:

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
That's excellent.

Another work round

go to x: () y: () // sprite1

(distance to [sprite1 v]) // sprite2

Charles12310 wrote:

So, how do they even know if that script is gonna work?

By testing.
Charles12310
Scratcher
1000+ posts

Distance to (x) (y)

walkcycle wrote:

Cub56 wrote:

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.

Sigton wrote:

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
That's excellent.

Another work round

go to x: () y: () // sprite1

(distance to [sprite1 v]) // sprite2

Charles12310 wrote:

So, how do they even know if that script is gonna work?

By testing.
Yes but that's like saying the workaround is easy. -_-

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.


A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!
Cub56
Scratcher
1000+ posts

Distance to (x) (y)

Charles12310 wrote:

Cub56 wrote:

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.
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?
It is only Pythagoras and I learnt it practically at the start of the equivalent of middle school.

Check out Life Raft Survival, my new advanced sandbox survival game with crafting, building, transportation, weather events, tropical storms, and more!

In the game you're stranded at sea after a mysterious crash and must survive in an unforgiving tropical island environment collecting resources and crafting, in an attempt to finally be rescued.



Charles12310
Scratcher
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!


A few internet communication companies want to corrupt the internet by getting rid of net neutrality. Stop Them!

Powered by DjangoBB