A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: enemy movement pattern

Threaded View

  1. #1
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693

    enemy movement pattern

    I don't know why but I cannot seem to figure out how to make a cosine(math term) like movement of an enemy... I'm just really stupid i guess... i tried the following code which just leads to some really weird movement:

    Code:
    //basically the code is supposed to make the enemy wave back and forth
    //as it moves down the screen, creating a cosine like effect
    //this.startX = where on the x axis the enemy starts
    //this.dFrmStart = the distance from the startX
    //this.maxDist = how far the enemy should go before it turns around
    //bgSpeed = background constant speed
    //this code tries to check how close enemy is till needing to turn and modifies
    //the enemies speed accordingly to make a curved looking turn
    //problem is, it doesnt work...
                                if(this._x>=this.startX){
    				this.dFrmStart=this._x-this.startX;
    			}else if(this.startX>this._x){
    				this.dFrmStart=this.startX-this._x;
    			}		
    			if(this.dFrmStart>this.maxDist){
    				this.speedX=this.speedX*(-1);
    			}
    			
    		if(this.dFrmStart==0){
    			this.dFrmStart=1;
    		}
    			this.speedMod = (this.dFrmStart/this.maxDist)
    			this.speedMod = 1 - this.speedMod;
    			if(this.speedMod<0.2){
    				this.speedMod=0.2;
    			}
    			if(this.speedMod==0){
    				this.speedMod=1;
    			}
    			
    			this._y+=(this.speed*this.speedMod)+bgSpeed;
    			this._x+=this.speedX*this.speedMod;
    I am kinda ashamed to show my attempt but just wanted people to see what I tried and that I'm not just asking for code without doing any work... Any tips would be wonderful...

    -ChaseNYC
    Last edited by ChaseNYC; 08-08-2006 at 07:54 PM.
    mmm signature

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