A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [AS3] Heat Seeking Missile

  1. #1
    Junior Member
    Join Date
    Jun 2004
    Posts
    27

    [AS3] Heat Seeking Missile

    Hi,

    I've looked up the AS2 Heat seeking missile example, but it doesn't work for my game. The position parameters are the target. This game is also a fully scrollable terrain jet fighter game. The Missile doesn't rotate in the correct direction, doesn't turn towards the target, for example if the target is behind the missile.

    Code:
    public function setGuidance(index:Number,posx:Number,posy:Number, rate:Number):void{
    			var it=index;
    			var disX = 0;
    			var disY = 0;
    			var disTot = 0;
    			var turnRate = rate;
    			var moveX = 0;
    			var moveY = 0;
    			var totalMov = 0;
    			var rot = 0;
    			var moveTot = 0;
    			
    				
    				if(this.missiles[it].launched && this.missiles[it].guidance){
    					
    					disX =  posx - (this.missiles[it].object as Bitmap).x;
    					disY =  posy - (this.missiles[it].object as Bitmap).y;
    					disTot = Math.sqrt(disX*disX + disY*disY);
    					
    					if(disTot <= 1000){
    						
    						rot = (this.missiles[it].object as Bitmap).rotation;
    						moveX = turnRate * (disX / disTot);
    						moveY = turnRate * (disY / disTot);
    						moveTot = Math.sqrt(moveX*moveX + moveY*moveY);
    						
    						this.missiles[it].xspeed+=moveX;
    						this.missiles[it].yspeed+=moveY;
    						
    						
    						moveX = this.missiles[it].xspeed*moveX / moveTot;
    						moveY = this.missiles[it].yspeed*moveY / moveTot;
    						
    						(this.missiles[it].object as Bitmap).x += moveX;
    						(this.missiles[it].object as Bitmap).y += moveY;
    						
    						(this.missiles[it].object as Bitmap).rotation =180*Math.atan2(moveY, moveX) / Math.PI;
    						
    						
    					}
    				}

  2. #2
    Senior Member
    Join Date
    Oct 2009
    Posts
    117
    Are those the stage positions or the map position?
    They need to be the stage positions, but you'll also need to continually compensate for the scrolling background each frame.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center