Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Patrick_Ascher

Hey there,
i searched about A* findings and i already find some good threads about it.

i read the a*Path thanks MikeL for the link

and i used the CODE of paularmstrong https://gist.github.com/994534

so i wanna make a click movement for my player first and then the following by the enemys.

so i started like this.
required the plugin and added this to my main.js init
ig.input.initMouse();
ig.input.bind( ig.KEY.MOUSE1, 'test' );

and in my player.js -> update i added following
	              if( ig.input.pressed('test')) {
	                  this.player = ig.game.getEntitiesByType(EntityPlayer)[0];
	                  this.mymouseposition = {pos:{x:ig.input.mouse.x+ig.game.screen.x,y:ig.input.mouse.y+ig.game.screen.y} };
	                  if (this.player && this.mymouseposition){
	                    this.path = new PathFinder(this.player,this.mymouseposition);
	                    this.points = this.path.getPath(); 
	                  }
	              }

if(this.points){
	this.moveTowardsDestination();
}

so i also added this to my player.js
	    moveTowardsDestination:function(){

	        var node = this.points[0];
	        this.multiplier = 10;

	        if(node.x < Math.floor(this.pos.x)){
	            this.vel.x = -20*this.multiplier;
	            this.currentAnim = this.anims.left;
	        }
	        
	        if(node.x > Math.floor(this.pos.x)){
	            this.vel.x = 20*this.multiplier;
	            this.currentAnim = this.anims.right;
	        }
	        
	        if(node.y > Math.floor(this.pos.y)){
	            this.vel.y = 20*this.multiplier;
	            this.currentAnim = this.anims.down;
	        }
	        
	        if(node.y < Math.floor(this.pos.y)){
	            this.vel.y = -20*this.multiplier;
	            this.currentAnim = this.anims.up;
	        }
	            
	        if(node.x == Math.floor(this.pos.x) && node.y == Math.floor(this.pos.y)){
	            if(this.points.length >1){
	            this.points.splice(0,1);
	            }else{
	            this.points = null;
	            }
	           
	        }
	        
	        },

so i am calculating the next movement - the actual pos.

So maybe i make a mistake with the call-up, becouse the player is moving but a little bit slow und buggy.

Maybe some of you know a good tutorial of it? Or let me know what´s my mistake.

Here a link to the game, that you can see the bugs by the movement:
demo

Regards
Patrick

1 decade ago by Patrick_Ascher

hello again,

can anybody tell me if the step after the pathifinding is right? because i am creating my own A* plugin but i think i have a problem with the movement because its lagging that much... so have i make it in the player update action like i do or should i do it in any other method???

thanks
patrick
Page 1 of 1
« first « previous next › last »