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

#1 2012-04-18 16:30:14

Rocket-Moon
New Scratcher
Registered: 2012-04-16
Posts: 14

Help With Enemy Movement

On this game im try to get he enemy to follow the player ONLY ON THE X AXIS. But i need it to be slower. Just so that the player can kill the enemy by jumping over.

Offline

 

#2 2012-04-19 07:12:33

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

Re: Help With Enemy Movement

X axis only:

forever
if <(x position) < ([x position v] of [Player v])> //if player is on my right
change x by [3] //change the 3 to change the speed
else
change x by [-3] //change the 3 to change the speed (again)
end

Offline

 

#3 2012-04-19 08:00:39

chipguy
Scratcher
Registered: 2009-09-09
Posts: 500+

Re: Help With Enemy Movement

Splodgey wrote:

X axis only:

forever
if <(x position) < ([x position v] of [Player v])> //if player is on my right
change x by [3] //change the 3 to change the speed
else
change x by [-3] //change the 3 to change the speed (again)
end

or you could try this:

forever
if<(x position) < ([x position v] of [Player v])>
change [x velocity v] by [0.5]
else
change [x velocity v] by [-0.5]
end
set [x velocity v] to ((x velocity) * [0.95])
change x by (x velocity)
that way the enemy uses velocities  big_smile

Last edited by chipguy (2012-04-19 08:01:52)


http://scratch.mit.edu/static/projects/chipguy/2919121_sm.png by yours truly  big_smile

Offline

 

#4 2012-04-19 12:58:15

Rocket-Moon
New Scratcher
Registered: 2012-04-16
Posts: 14

Re: Help With Enemy Movement

Thank You So Muchhhh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Offline

 

#5 2012-04-19 14:21:17

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

Re: Help With Enemy Movement

chipguy wrote:

Splodgey wrote:

X axis only:

forever
if <(x position) < ([x position v] of [Player v])> //if player is on my right
change x by [3] //change the 3 to change the speed
else
change x by [-3] //change the 3 to change the speed (again)
end

or you could try this:

forever
if <(x velocity) < (max speed)>
if<(x position) < ([x position v] of [Player v])>
change [x velocity v] by [0.5] //accelerates by changing x speed
else
change [x velocity v] by [-0.5]
end
end
set [x velocity v] to ((x velocity) * [0.95]) //change the 0.95 to change how fast it slows down (the smaller the quicker)
change x by (x velocity) //changes x by x speed
that way the enemy uses velocities  big_smile

I would have done that but I was trying to keep it simple. Also, I explained how to customize it and added a maximum speed

Offline

 

#6 2012-04-19 14:38:13

Rocket-Moon
New Scratcher
Registered: 2012-04-16
Posts: 14

Re: Help With Enemy Movement

Just asking, how do i get it to die?

Offline

 

#7 2012-04-20 02:14:42

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

Re: Help With Enemy Movement

Rocket-Moon wrote:

Just asking, how do i get it to die?

There are 2 ways you could do this:

when i die
death screen or whatever
stop all
or
repeat until <dead?> //use that instead of forever dead could be lives = 0 or something
end
death screen or whatever

Last edited by Splodgey (2012-04-20 02:14:58)

Offline

 

#8 2012-04-21 05:46:06

Rocket-Moon
New Scratcher
Registered: 2012-04-16
Posts: 14

Re: Help With Enemy Movement

thx

Offline

 

Board footer