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

#1 2008-06-15 11:38:43

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Getting closest sprite

Is there a way for a sprite to know which sprite is the closest to him? I mean, without having to check for every single sprite and then without having to know in advance all sprite names.

I'm thinking of a script associated with a sprite that, once you duplicate the sprite several times, would be able to let the sprite know which sprite is the closest to him.

Offline

 

#2 2008-06-15 11:39:38

Bluestribute
Scratcher
Registered: 2008-01-24
Posts: 1000+

Re: Getting closest sprite

That would probably be possible


http://img247.imageshack.us/img247/1204/bluestributett4.jpg
That's my PSN ID. I know tons of COD4 glitches. Add me as your friend. Oh, and get a headset

Offline

 

#3 2008-06-15 13:00:28

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Getting closest sprite

You could work the project backwards:  Let's say you have a bunch of Target sprites and one Hero sprite.  Each Target sprite could compute the distance to the Hero sprite (when requested by a broadcast message) and, if it is smaller than a global variable called Distance, replace that value with a new shortest distance.  The target sprite could also update a couple of location variables X_Closest and Y_Closest at the same time.  Then, whenever the Hero wanted to know which Target was closest, it would simply send out a message and then head towards X_Closest,Y_Closest.    Would that work for what you are trying to do?


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#4 2008-06-15 18:59:10

chalkmarrow
Scratcher
Registered: 2007-05-18
Posts: 100+

Re: Getting closest sprite

Paddle2See beat me to it. I think his idea is exactly the way I would do it. I was considering doing a simulation once of group behavior of birds (google "Boids" for a good example) and I think that's the way I started to do it.

Offline

 

#5 2008-06-15 19:25:59

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Getting closest sprite

chalkmarrow wrote:

Paddle2See beat me to it. I think his idea is exactly the way I would do it. I was considering doing a simulation once of group behavior of birds (google "Boids" for a good example) and I think that's the way I started to do it.

I've been thinking about Boids for quite awhile!  Flocking behavior and all that...it would be cool.  I haven't made any real progress on it though.  Probably shouldn't be hijacking this thread...


http://i39.tinypic.com/2nav6o7.gif

Offline

 

#6 2008-06-17 04:48:13

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: Getting closest sprite

Thanks for replying to this "weird" topic of mine, Paddle2See and Chalkmarrow.

I had thought of the "many-to-one" strategy (as opposed to the "one-to-many" that forces to know in advance the name of all sprites). But what I was thinking in reality is a "many-to-many" search for the closest sprite. In this case I have no hero (or many heroes)

Do you think that this is possible? Or more classical programming instruments (such as arrays or lists) are needed?

I think that a very nice possibility that should seriously considered to be added to Scratch is a "duplicate" command that would allow a sprite to duplicate itself. But allowing this, a sprite cannot know in advance the names of all other spirtes. What do you think?

(btw: why I didn't receive a copy of your replies by email? how do I subscribe to this topic?)

Offline

 

#7 2008-06-17 04:51:50

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: Getting closest sprite

s_federici wrote:

I think that a very nice possibility that should seriously considered to be added to Scratch is a "duplicate" command that would allow a sprite to duplicate itself. But allowing this, a sprite cannot know in advance the names of all other spirtes. What do you think?

Or also a "duplicate sprite #..." (i.e. the duplication of a given sprite performed by another sprite) could be a nice addition. Even if you could always send a message to the "duplicable" sprite that would decide by itself if it would like to be duplicated. This would make object-orientation safer, I guess.

Offline

 

#8 2008-06-17 07:05:06

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: Getting closest sprite

I haven't been able to come up with a good solution to the many-to-many problem.  I think it would require arrays and sorting to do. 

As far as subscribing to this topic, I believe that Andres had to disable Subscribe when they moved to a new server.  I don't think that problem is fixed yet.


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer