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
and in my player.js -> update i added following
so i also added this to my player.js
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
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