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

#1 2009-12-23 04:15:31

diywid
Scratcher
Registered: 2009-10-27
Posts: 76

How to make one sprite follow another

As I'm making a platformer with a good guy and bad guys, I want to know how to make it so the bad guy (computer controlled) follows the good guy (player controlled.) I want it so it is as if the good guy is getting chased, and the bad guy tries to keep up with him.
Any help on how to program this would be appreciated.

Offline

 

#2 2009-12-23 11:39:56

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: How to make one sprite follow another

What you're asking for is pretty advanced. However, there is a way you can simplify it a lot and keep artificial intellignece out of it. Just use this.

(Bad Guy Script)
<when green flag clicked>
<forever>
<point towards( Good Guy
<move( 2 )steps>

Offline

 

#3 2009-12-24 05:30:05

diywid
Scratcher
Registered: 2009-10-27
Posts: 76

Re: How to make one sprite follow another

Thanks, I didn't need anything too advanced so that'll be fine.

Edit: It's working fine, I've just gotta mess around with the [blocks] <move( x )steps> [/blocks] because the idea is when the good guy touches the bad guy he loses so I don't want the bad guy to be too quick.

Last edited by diywid (2009-12-24 05:43:38)

Offline

 

#4 2009-12-24 13:30:36

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: How to make one sprite follow another

You probably don't want to make it too realistic, but you could make the guy steadily slow down or speed up I you used a script like this:
(Same code as before but move (variable) steps)
When green flag clicked
Set variable to --
Forever
Wait 1 second
Change variable by --

Offline

 

#5 2010-05-18 18:32:24

adiguy17
Scratcher
Registered: 2010-05-04
Posts: 17

Re: How to make one sprite follow another

<forever if>

Offline

 

#6 2010-05-18 18:39:44

infinitum3d
Scratcher
Registered: 2009-05-10
Posts: 100+

Re: How to make one sprite follow another

You may be able to  use the DISTANCE TO sensor. 



<forever>
<if> <( <distance to[ goodGuySprite ] <>>  50  )>
<move( 10 )steps>
<else>
<move( 2 )steps>

Last edited by infinitum3d (2010-05-18 18:43:21)

Offline

 

#7 2010-06-21 11:51:25

Joelly
New Scratcher
Registered: 2010-06-21
Posts: 4

Re: How to make one sprite follow another

hi mine is similar to this but mine is pacman i have already done the above but he goes through the wall and i dont no how to make him go around the wall instead of through it, would you be able to help me on this?

Offline

 

#8 2010-06-21 12:22:39

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: How to make one sprite follow another

Joelly wrote:

hi mine is similar to this but mine is pacman i have already done the above but he goes through the wall and i dont no how to make him go around the wall instead of through it, would you be able to help me on this?

Welcome to Scratch! That's pretty complicated stuff right there. You would have to use a pathfinding AI for the enemy to find its way to pacman. It might be a little too advanced.

Offline

 

#9 2010-06-21 15:57:51

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: How to make one sprite follow another

shadow_7283 wrote:

Joelly wrote:

hi mine is similar to this but mine is pacman i have already done the above but he goes through the wall and i dont no how to make him go around the wall instead of through it, would you be able to help me on this?

Welcome to Scratch! That's pretty complicated stuff right there. You would have to use a pathfinding AI for the enemy to find its way to pacman. It might be a little too advanced.

It's definitely pretty advanced, especially for a beginner Scratcher. In fact, it's quite difficult to make an object follow a stationary object through a maze, let alone a moving one... It's probably possible, but nobody's done it in Scratch. I made a pathing AI a few weeks ago which gets from point A to point B flawlessly (here), but it's a little bit slower than would probably be fit for a Pac-Man game...

Offline

 

#10 2010-06-22 03:36:22

Joelly
New Scratcher
Registered: 2010-06-21
Posts: 4

Re: How to make one sprite follow another

ok thanks guys and if you found out how to do it just let me know please
thanks

Offline

 

#11 2010-06-22 03:49:53

Joelly
New Scratcher
Registered: 2010-06-21
Posts: 4

Re: How to make one sprite follow another

another thing how would you make the ghost bounce off the walls not the egde of the screen but the walls?

Offline

 

#12 2010-08-26 18:09:36

krypto9000
Scratcher
Registered: 2010-08-25
Posts: 3

Re: How to make one sprite follow another

http://scratch.mit.edu/forums/viewtopic.php?id=27665#req_messhttp://scratch.mit.edu/forums/viewtopic.php?id=27665#req_messageagehttp://scratch.mit.edu/forums/viewtopic.php?id=27665#req_messagehttp://scratch.mit.edu/forums/viewtopic.php?id=27665#req_messagehttp://scratch.mit.edu/forums/viewtopic.php?id=27665#req_message


sad  ,  neutral  ,  hmm  ,  smile  ,  yikes  ,  lol  ,  big_smile        J@Y!!!

Offline

 

#13 2010-08-26 23:39:28

Locomule
Scratcher
Registered: 2009-08-24
Posts: 500+

Re: How to make one sprite follow another

Joelly wrote:

hi mine is similar to this but mine is pacman i have already done the above but he goes through the wall and i dont no how to make him go around the wall instead of through it, would you be able to help me on this?

You're not gonna like it but here is most of what you need to know. Not that this is the only way, just how to make it act like the original game...
http://scratch.mit.edu/forums/viewtopic.php?id=43590
this covers movement and AI btw

Last edited by Locomule (2010-08-26 23:40:09)


aka Pain from DragonSpires, Delrith Online, BotBattle, Urban Dead etc etc lol

Offline

 

Board footer