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
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...
Offline
seraine wrote:
What is sine and cosine?
They're used in trigonometry. They help you work out angles and sides of triangles
Offline
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)
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:
That should work like a beauty.
Hope I helped!
Offline
Sniff sniff...
After all my hard work, this thread whooshed down to the bottom of the page
Offline