YuShaN Posted November 11, 2015 Share Posted November 11, 2015 I making a game shooting. I want my bullet auto chase enemy. But my bullet just chase only a type enemy. Someone help me. This is my codehttp://phaser.io/sandbox/edit/yYKCNlHn Link to comment Share on other sites More sharing options...
Skeptron Posted November 11, 2015 Share Posted November 11, 2015 Yeah it's normal. At the end of your update() function you call launchEnemy(), which will populate the enemy var, and them launchEnemy2(), which will populate the same enemy var (and thus override previous assignment). And at next update, first thing you do is fire bullets at the enemy var. So enemy var will always be populated last by the launchEnemy2() method, that is, with enemy2 enemies. Link to comment Share on other sites More sharing options...
YuShaN Posted November 11, 2015 Author Share Posted November 11, 2015 Yeah it's normal. At the end of your update() function you call launchEnemy(), which will populate the enemy var, and them launchEnemy2(), which will populate the same enemy var (and thus override previous assignment). And at next update, first thing you do is fire bullets at the enemy var. So enemy var will always be populated last by the launchEnemy2() method, that is, with enemy2 enemies.I understand but how to fix it Link to comment Share on other sites More sharing options...
YuShaN Posted November 11, 2015 Author Share Posted November 11, 2015 I found this way fix it Thanks for reading. Link to comment Share on other sites More sharing options...
Skeptron Posted November 11, 2015 Share Posted November 11, 2015 Here I did a naïve implementation : http://phaser.io/sandbox/edit/ldundtvm Don't forget to mark the post as answered if you're happy with the solution. YuShaN 1 Link to comment Share on other sites More sharing options...
YuShaN Posted November 11, 2015 Author Share Posted November 11, 2015 Here I did a naïve implementation : http://phaser.io/sandbox/edit/ldundtvm Don't forget to mark the post as answered if you're happy with the solution.But your bullet just chase a type enemy Link to comment Share on other sites More sharing options...
Skeptron Posted November 11, 2015 Share Posted November 11, 2015 Yeah sorry my bad! Change Math.floor() for Math.round() (it was always picked childAt(0), that is, first enemys group). http://phaser.io/sandbox/edit/ldundtvm YuShaN 1 Link to comment Share on other sites More sharing options...
YuShaN Posted November 11, 2015 Author Share Posted November 11, 2015 Yeah sorry my bad! Change Math.floor() for Math.round() (it was always picked childAt(0), that is, first enemys group). http://phaser.io/sandbox/edit/ldundtvmThis is my code. What do you think about it http://phaser.io/sandbox/edit/yYKCNlHn Link to comment Share on other sites More sharing options...
Skeptron Posted November 11, 2015 Share Posted November 11, 2015 It also does the trick! But damn this game is gonna be easy. Poor enemies getting destroyed! xD Link to comment Share on other sites More sharing options...
YuShaN Posted November 11, 2015 Author Share Posted November 11, 2015 Can do bullet chase for enemy nearest? Link to comment Share on other sites More sharing options...
Skeptron Posted November 11, 2015 Share Posted November 11, 2015 Yeah! Or just slow down the bullets. Link to comment Share on other sites More sharing options...
YuShaN Posted November 11, 2015 Author Share Posted November 11, 2015 Yeah! Or just slow down the bullets.use update function make bullet fly zik zak Link to comment Share on other sites More sharing options...
Recommended Posts