narukaioh Posted October 11, 2014 Share Posted October 11, 2014 Hi guys! I'm trying to create artificial intelligence of the enemies of my game, and I'm finding it difficult to create a method that makes the enemy feel the presence of the player to follow and attack him as well. I tried to group a geometric shape of a circle and a sprite both positioned at the same coordinates, however checked the documentation I can not use this form. It needs to be a group and / or a sprite. What can I do? The attached image shows the idea of what I do Link to comment Share on other sites More sharing options...
JUL Posted October 11, 2014 Share Posted October 11, 2014 if(enemy.inCamera && player.inCamera){} narukaioh 1 Link to comment Share on other sites More sharing options...
j0hnskot Posted October 11, 2014 Share Posted October 11, 2014 One idea is to check the distance between the enemy sprite and the player using Phaser.Math.distance enemies.forEachAlive(function(enemy) { if(!enemy.inCamera)return; //go to the next enemy if the current selected is out of the camera if (game.math.distance(enemy.x, enemy.y , player.x , player, y ) < 50 ) { //the enemy is near the player //do things } }, this);tweak the "50" value in the if check to find the desired distance. Be sure to check Phaser.Math . You may find something more suited for your needs. valueerror and narukaioh 2 Link to comment Share on other sites More sharing options...
narukaioh Posted October 11, 2014 Author Share Posted October 11, 2014 Oh!!! Thanks!!! I will try to do this! Link to comment Share on other sites More sharing options...
Recommended Posts