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

#1 2012-03-22 00:53:59

davidarmend
New Scratcher
Registered: 2012-03-22
Posts: 1

How do i make enemies follow a character? Details inside.

So i am making a game similar to metal slug, which is a game made on Scratch. It would be extremely helpful to play the game for a few seconds before answering. So basically the character does not change 'Y' position, but only 'X' position. (This means that the character only moves left to right on the screen, not up or down.) how do i make it so that multiple enemies will come out from each side and move towards the character? I have been thinking of using 'Glide', but my main question is how do i make multiple enemies that look exactly the same come out simultaneously?

Offline

 

#2 2012-03-22 06:35:55

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: How do i make enemies follow a character? Details inside.

OK, this might work; (sorry, it's a little complex - maybe too complex)

when gf clicked //x velocity is "for this sprite only"
forever
set [enemy count v] to [0] //"for this sprite only"
repeat (length of [enemies v]) //basically check if I'm touching any enemies...
change [enemy count v] by [1]
if <touching (item (enemy count) of [enemies v])?>
if <(x position) < ([x position v] of [player v])> //if I'm on the left of the enemy
if <(x velocity) > [0]> //and I'm moving right (towards it)
set [x velocity v] to [0] // stop
end
else //on my right?
if <(x velocity) > [0]> //and I'm moving left (towards it)
set [x velocity v] to [0] // stop
end
end
end
end
if <(x position) < ([x position v] of [player v])> //if I'm on the left of the player
set [x velocity v] to [4] // set my x speed to 4 (change it to adjust speed)
else
set [x velocity v] to [-4] //set my x speed to -4 (moves left)
end
change x by (x velocity) //change x by x speed
To add enemies, just use this:
add [SPRITE NAME OF ENEMY HERE] to [enemies v]
was this what your looking for?

Offline

 

#3 2012-04-03 17:27:26

aryabtsev
Scratcher
Registered: 2012-02-05
Posts: 81

Re: How do i make enemies follow a character? Details inside.

Splodgey wrote:

if <touching (item (enemy count) of [enemies v])?>

There are no lists of sprites, are there? So you can't script: touching variable.

I would make an enemy1 sprite that goes to one side of the screen and then something like this:

repeat until <touching [player v]?>
   point towards [player v]
   move (0.5) steps //change this to whatever speed you want
end
Than duplicate the sprite many times, make them appear from different places.
Scratch on!


http://i.imgur.com/NX7AO.jpg

Offline

 

#4 2012-04-04 03:12:57

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: How do i make enemies follow a character? Details inside.

aryabtsev wrote:

Splodgey wrote:

if <touching (item (enemy count) of [enemies v])?>

There are no lists of sprites, are there? So you can't script: touching variable.

*Facepalm* Your supposed to add all the enemy sprite names to the list. It's kinda like a "Sprite Class". If you see what I mean...

Also, mine makes enemies "bump" into each other.

aryabtsev wrote:

Splodgey wrote:

if <touching (item (enemy count) of [enemies v])?>

repeat until <touching [player v]?>
   point towards [player v]
   move (0.5) steps //change this to whatever speed you want
end
Then duplicate the sprite many times, make them appear from different places.
Scratch on!

It moves left/right. What if the enemies are a different height to the player?

if <(x position) < ([x position v] of [player v])> //if the player's on my right
wait (0.5) secs //makes it more realistic, if you jump over something, it will take about 0.5 secs to realise what's
point in direction [90 v] //happened (from above)
else
wait (0.5) secs
point in direction [-90 v]

Last edited by Splodgey (2012-04-04 14:23:11)

Offline

 

#5 2012-04-04 13:26:42

aryabtsev
Scratcher
Registered: 2012-02-05
Posts: 81

Re: How do i make enemies follow a character? Details inside.

Splodgey wrote:

Your supposed to add all the enemy sprite names to the list. It's kinda like a "Sprite Class".

Oh, I get it. Sorry.


http://i.imgur.com/NX7AO.jpg

Offline

 

#6 2012-04-04 14:32:56

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: How do i make enemies follow a character? Details inside.

Draw enemy

when gf clicked
set (side) to (pick random 0 to 1)
if <(side) = 1>
   set x to [240]
else
set x to [-240] 
end
forever
   glide (x position of player) for (speed) seconds
duplicate the sprite


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

Board footer