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
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
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
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
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
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
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
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
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
Offline
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)
Offline