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

#1 2012-02-29 15:57:20

dayd4670
New Scratcher
Registered: 2010-12-04
Posts: 8

Chasing multiple sprites

Ok, so I am making a zombie apocalypse game. However, I'm having some trouble trying to get the zombie to chase people. I want the zombie to chase any of the people that get near it, but I don't won't to make a ?

distance to [person v]
for every single person I make. Is there any way I can make 1 ?
distance to [person v]
work for all of the people?

Offline

 

#2 2012-03-01 04:19:24

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Chasing multiple sprites

Nope. D: Sometimes you just have to tough it out.

Offline

 

#3 2012-03-01 13:41:22

dayd4670
New Scratcher
Registered: 2010-12-04
Posts: 8

Re: Chasing multiple sprites

Oh.  sad  Well, that sucks.

Offline

 

#4 2012-03-01 16:19:47

turkey3
Scratcher
Registered: 2011-12-04
Posts: 500+

Re: Chasing multiple sprites

I can't think of anyhing

Offline

 

#5 2012-03-01 16:28:41

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Chasing multiple sprites

Not really.  You could put all of the distances in a list with a loop and look for the lowest number  hmm


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#6 2012-03-01 19:43:43

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Chasing multiple sprites

Well you could name the people "1", "2", "3", etc.  Then you use the script:

when gf clicked
set [chase v] to (0)
forever
  set [min-dist v] to (1000)
  set [sprite v] to (0)
  change [sprite v] by (1)
  if <(distance to (sprite)) < (min-dist)>
    set [min-dist v] to (distance to (sprite))
    set [chase v] to (sprite)
  end
  change [sprite v] by (1)
  if <(distance to (sprite)) < (min-dist)>
    set [min-dist v] to (distance to (sprite))
    set [chase v] to (sprite)
  end
  change [sprite v] by (1)
  if <(distance to (sprite)) < (min-dist)>
    set [min-dist v] to (distance to (sprite))
    set [chase v] to (sprite)
  end
  change [sprite v] by (1)
  if <(distance to (sprite)) < (min-dist)>
    set [min-dist v] to (distance to (sprite))
    set [chase v] to (sprite)
  end
  change [sprite v] by (1)
  if <(distance to (sprite)) < (min-dist)>
    set [min-dist v] to (distance to (sprite))
    set [chase v] to (sprite)
  end
  if <(chase) > (0)>
    point towards (chase)
    move (5) steps
  end
end

And this way, you only have to copy and paste the middle thing as many times as you need to, instead of doing each individual.

Last edited by AtomicBawm3 (2012-03-01 19:48:34)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

Board footer