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:43:13

steppenwulf
Scratcher
Registered: 2009-07-23
Posts: 1000+

How do you make a sprite point torwards the nearest sprite to it?

Help would be much appreciated.  smile


I'm graduating HS this April and going to college in the Fall.

Offline

 

#2 2009-10-15 15:50:00

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

Re: How do you make a sprite point torwards the nearest sprite to it?

Just get a list of distances and pick the smallest value.

Don't try it with more than about 20 sprites or it will probably lag too much.


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 15:52:32

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do you make a sprite point torwards the nearest sprite to it?

[blocks]
<when green flag clicked>
[add  <distance to[ sprite2 ]> to [List] ]
[add  <distance to[ sprite3 ]> to [List] ]
-So on so forth-
<set{ Line  }to( 2 )>
<set{ Lowest  }to( ( Item 1 of [ List ] ) )>
<repeat( Length of [ List ] )>
<if><( (Item (Line) of [List] <<> <{ Lowest  }> )>
<set{ Lowest  }to( ( Item (Line) of [ List ] ) )>
<end>
<change{ Line  }by( 1 )>
<end>
<say[  <{ Lowest  }> ]>
[/blocks]

Does that help?  smile  I'll create a project.  smile

Project: http://scratch.mit.edu/projects/Magnie/718306

Last edited by Magnie (2009-10-15 16:05:55)

Offline

 

#4 2009-10-15 16:29:22

fg123
Scratcher
Registered: 2008-11-13
Posts: 1000+

Re: How do you make a sprite point torwards the nearest sprite to it?

Thanks magnie for replying.


Hai.

Offline

 

#5 2009-10-15 17:01:28

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do you make a sprite point torwards the nearest sprite to it?

No problem, but I reliazed it's not exactly what you want, you'll need to add stuff on the bottom for the main sprite to point towards the closest sprite.

Offline

 

#6 2009-10-15 18:15:18

steppenwulf
Scratcher
Registered: 2009-07-23
Posts: 1000+

Re: How do you make a sprite point torwards the nearest sprite to it?

archmage wrote:

Just get a list of distances and pick the smallest value.

Don't try it with more than about 20 sprites or it will probably lag too much.

I'm not really sure how to do that. Btw thanks for the tip. Could you show me how to do that please?


I'm graduating HS this April and going to college in the Fall.

Offline

 

#7 2009-10-15 18:40:10

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

Re: How do you make a sprite point torwards the nearest sprite to it?

Magie wrote the exact script you need to use


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

 

Board footer