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

#1 2012-07-27 18:34:48

chrisbown
Scratcher
Registered: 2011-07-29
Posts: 100+

chasing in scrolling

i am trying to make a scrolling game but i want enemies chasing the player , anyone know how to do this.


check out this: Tank physicshttp://scratch.mit.edu/projects/hamstercake11/3082288

Offline

 

#2 2012-07-27 19:19:26

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: chasing in scrolling

You will need variables for the enemy (I like to call them "h" and "k") that are the enemy's coordinates on the scrolling terrain. use this script.

when gf clicked
forever
go to x:((h) - (x-scroll)) y:(k)
if <touching [edge v]?>
hide
else
show
end
To make the enemy chase the player use this script below.
when gf clicked
forever if <not <touching [edge v]?>>
if <([x position v] of [player v]) > (x position)>
change [hvel v] by (1)
else
change [hvel v] by (-1)
end
set [hvel v] to ((hvel) * [0.9]) // can use other fractions to change speed
change [h v] by (hvel)

Last edited by Wes64 (2012-07-27 19:20:01)


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#3 2012-07-27 20:04:16

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

Re: chasing in scrolling

Wes64 wrote:

You will need variables for the enemy (I like to call them "h" and "k") that are the enemy's coordinates on the scrolling terrain. use this script.

when gf clicked
forever
go to x:((h) - (x-scroll)) y:(k)
if <touching [edge v]?>
hide
else
show
end
To make the enemy chase the player use this script below.
when gf clicked
forever if <not <touching [edge v]?>>
if <([x position v] of [player v]) > (x position)>
change [hvel v] by (1)
else
change [hvel v] by (-1)
end
set [hvel v] to ((hvel) * [0.9]) // can use other fractions to change speed
change [h v] by (hvel)

You'd need the enemy to react the opposite way to you when you move, so right arrow moves the enemy left


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

Offline

 

#4 2012-07-27 20:28:17

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: chasing in scrolling

zammer990 wrote:

You'd need the enemy to react the opposite way to you when you move, so right arrow moves the enemy left

I dont think you understand the script. These are for the enemy, the (x-scroll) variable is the player's position. These work for both directions.


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

Board footer