I am trying to create a homing missile in AS3. It is easy enough when you want it to just perfectly follow the point - but I'm trying to make the rockets turn around if the target (target) bypasses it.
Here's what I have - it almost works, but, as you can see, it is pretty buggy (especially if the mouse is on the left rocket (it seems to work fine if it moves to the right).
http://projectavian.com/rocket.swf
Here is my Rocket class:
package { import flash.display.Sprite; import flash.geom.Point; import flash.events.Event; public class Rocket extends Sprite {
I assume that this logic does not support everything that makes the rocket act strangely, moving to the left:
if(_ang > _destAng) _ang -= _steer; if(_ang < _destAng) _ang += _steer;
Here is the code I used to create the Rocket, if useful:
var point:Point = new Point(); var rocket:Rocket = new Rocket(); rocket.target = point; addChild(rocket); addEventListener(Event.ENTER_FRAME, _handle); function _handle(e:Event):void { point.x = mouseX; point.y = mouseY; }
Marty source share