A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: enemy movement pattern

  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

  2. #2
    Axis Games Djugan's Avatar
    Join Date
    Oct 2003
    Posts
    238
    It's kinda hard to tell what you've got going on without seeing all the code. Perhaps attaching the .fla would be helpful.

  3. #3
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    ummm i'd rather not post it because there is a ton of work put into other parts of the game... I guess truth is that code is of no relevance because it doesnt at all achieve what its supposed to but I will edit original post to have comments explaining it all...
    mmm signature

  4. #4
    Flash Incompetent ChaseNYC's Avatar
    Join Date
    Jun 2002
    Location
    new york city
    Posts
    693
    sorry for the bump... no one has any help, advice, pointers to put me in the right direction?
    mmm signature

  5. #5
    Wait- what now? tidenburg's Avatar
    Join Date
    Dec 2005
    Posts
    1,471
    it would help to know what is going wrong. Is it a syntax error or does the object do somthing completly different or it does do anything at all?
    Copy the frame into a blank fla and remove unnecassary stuff like graphics etc. That way you can post it and no-one can steal any of it.

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