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

#1 2013-01-09 17:06:13

Pauley
New Scratcher
Registered: 2013-01-09
Posts: 1

Help With AI script

How do i move along enemies with the background? It is a vertical scrolling game.  have the randomization down, however, im not sure how to make them scroll vertically with the background? help please:)
The code I used for my background is below if it helps at all.

when gf clicked
forever
set x to <[0]>
switch to costume <(terrain#)>
set y to <(scrollY)> + <[360]> * <(terrain#)> - <[1]>
end

Offline

 

#2 2013-01-09 18:29:01

RenOkshadia3537
New Scratcher
Registered: 2013-01-09
Posts: 33

Re: Help With AI script

You need to have two variables for every enemy, and then easily use this script:

when gf clicked
set [enemyY v] to [it's position on the y axis]
forever
set x to <(x position) + (pick random (2) to (-2))> //so that the enemy's move randomly across the x axis
set y to (((360)*(terrain you want it to start from)) - (enemyY))
change [enemyY v] by [however much you want]
end
What that does, is it gets the starting amount (360*terrain12), and then it gets the offset (enemyY), and it adds/subtracts the offset to it. Depending on how you want the Y axis to work, you may have to change the subtraction to addition.

I hope this helps  smile

Offline

 

Board footer