alright, say im making a missile weapon for a shooter game that rotates its position to follow a specific target. The missile finds an exact rotation position to the target, the rocket eases its rotation towards this value and thrusts in the direction of its physical rotation.
This is my code so far:
//wayP is the specified target
//rot is the targeted rotation
this.onEnterFrame=function(){
dx=this._x-_root.wayP._x
dy=this._y-_root.wayP._y
radians=Math.atan2(dy,dx)
rot=360*radians/(2*Math.PI)
this._rotation-=(this._rotation-rot)/8
this._x-=Math.cos(this._rotation/360*(2*Math.PI))*speed
this._y-=Math.sin(this._rotation/360*(2*Math.PI))*speed
}
my problem is that it often cant decide wether to go left or right to rotate to sync the rotation quickest and thus flutters endlessly in confusion. I need to figure a way to choose a direction for it while keeping the easing effect ive got. If anyones got a solution to this or a link to a good demonstration and sourse code it would be muchly appreciated because id love to make this a feature in my next game.
thanks in advance
btw; the swf demonstrates some extra code that sets speed according to distance, its target is the little rectangle.