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:
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...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;
-ChaseNYC




Reply With Quote