This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2009-10-15 15:10:14

Ssbrawl700
Scratcher
Registered: 2009-02-11
Posts: 100+

How do u calculate distance

Like the title says how do u calculate distance WITHOUT using the "distance to" block. I making a scrolling game so many blocks are useless and the distance to block is one of them. Any help is appreciated.

         -thank you


Can you beat the ever-so challenging Keyboard Khaos?

Offline

 

#2 2009-10-15 15:16:07

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: How do u calculate distance

set a to (sprite1X-sprite2X)
set b to (sprite1Y-sprite2Y)
set distance to (sqrt((a*a)+(b*b)))

There you go


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#3 2009-10-15 16:46:48

songhead95
Scratcher
Registered: 2008-03-19
Posts: 100+

Re: How do u calculate distance

archmage wrote:

set a to (sprite1X-sprite2X)
set b to (sprite1Y-sprite2Y)
set distance to (sqrt((a*a)+(b*b)))

There you go

^  ^  ^  ^
|  |  |  |

Pythagorean theorum

Last edited by songhead95 (2009-10-15 16:47:01)

Offline

 

#4 2009-10-15 21:16:57

TheSaint
Scratcher
Registered: 2008-11-04
Posts: 1000+

Re: How do u calculate distance

songhead95 wrote:

archmage wrote:

set a to (sprite1X-sprite2X)
set b to (sprite1Y-sprite2Y)
set distance to (sqrt((a*a)+(b*b)))

There you go

^  ^  ^  ^
|  |  |  |

Pythagorean theorum

Yeah, pretty much. As way to do it without the variables:

Set Distance to Sqrt ( (x2-x1)(x2-x1)+ (y2-y1)(y2-y1))

Offline

 

Board footer