PDA

View Full Version : flying/floating enemys


killingdyl
02-26-2008, 01:29 AM
okay so i got the action script. but the longer it goes, the monster gets farther away. How do i fix that.

26134

rrh
02-26-2008, 05:10 PM
I tried it and got the opposite; the arrow got closer to the ball over time.

Maybe give the speed a maximum speed?

MAXSPEED=20;
_x -= Math.max(Math.min(diffx / speed,MAXSPEED),-MAXSPEED);
_y -= Math.max(Math.min(diffy / speed,MAXSPEED),-MAXSPEED);

killingdyl
02-27-2008, 04:27 AM
i tried the actionscript and it worked when i changed the speed to 1 and maxspeed to 15. but when i started to have the ball move, the actionscript started to get messed up.

Thanks in advance

rrh
02-27-2008, 03:53 PM
What I usually do with moving things is give them a dx and dy to hold the current speed, and then add and subtract from dx and dy to accelerate towards the desired location or the desired speed.

You could also try making something where the change in behaviour is controlled by the distance from the ball, rather than by the current frame. That will be naturally resistant to drifting further away.

ASWC
02-27-2008, 04:33 PM
You can use my tutorial to check the distance between them:

http://www.actionscript.org/resources/articles/730/2/Drawing-lines-with-AS2/Page2.html

then make it do something if the distance goes over the limit you decide....

killingdyl
03-04-2008, 12:31 AM
ok so i saw the tutorial but how do i make it so that if the line gets too long(say 150 pixels) circle 2(or for my game the arrow) move closer to circle 1?