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

#1 2011-04-30 11:55:27

seraine
New Scratcher
Registered: 2011-04-27
Posts: 8

Enemy Scrolling

I have been trying to get a enemy to scroll- but not in a side to side way. Rather, I want the enemy to always move towards me in a game that has Scroll X and Scroll Y. All I can think of is that there'll have to be a variable that tells how "far" away the hero is and then have the enemy move closer.

Does anyone have any ideas?

Offline

 

#2 2011-04-30 13:43:44

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: Enemy Scrolling

The enemy will need an X and Y variable, and you'll have to use sine and cosine to have the enemy accurately point and move towards you, though just using the point towards will probably be accurate enough.  The problem being that if the enemy is off the screen, the real X and Y coordinates will be used to "point" towards you, not the X and Y coordinates of the scroller.  I hope that made sense.  It'll become really tricky if you start adding walls...


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#3 2011-05-01 14:31:28

seraine
New Scratcher
Registered: 2011-04-27
Posts: 8

Re: Enemy Scrolling

What is sine and cosine?

Offline

 

#4 2011-05-01 15:04:22

markyparky56
Scratcher
Registered: 2008-03-20
Posts: 1000+

Re: Enemy Scrolling

seraine wrote:

What is sine and cosine?

They're used in trigonometry. They help you work out angles and sides of triangles


http://j.mp/jgVnTq
Check out my game engine development site: NewDawn I'm a Level 171 Scratcher.I am http://bit.ly/nkvLNT

Offline

 

#5 2011-05-01 16:05:24

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Enemy Scrolling

I'll try and help best I can.

You will need to use two private X and Y variables in the enemy sprite, and make it scroll like a terrain but adding the X and Y.

So it should look something like this (of course, with different numbers)
http://dl.dropbox.com/u/11532575/forums/scrollwpr.gif

With that script in place, you're free to change the private X and Y of the enemy as if it were the real X and Y, and it would always stay relative to the terrain.

Then, for the pointing towards the sprite, a "point towards" wouldn't work well enough. You need to use trigonometry, as MoreGamesNow mentioned. I'm not very experienced with trig, but I'll try:

http://dl.dropbox.com/u/11532575/forums/scrollpointt.gif

That should work like a beauty.
Hope I helped!  smile

Offline

 

#6 2011-05-02 15:44:18

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Enemy Scrolling

Sniff sniff...
After all my hard work, this thread whooshed down to the bottom of the page  tongue

Offline

 

Board footer