woratana Posted December 17, 2013 Share Posted December 17, 2013 Hello, I was studying from code in 'Tanks' example game that came with Phaser package in github. I was looking for line of code that set speed of enemy's bullet and how it shoot to player. I found this very line:bullet.rotation = this.game.physics.moveToObject(bullet, this.player, 500);It comes out that this line makes the bullet shoot to player. In my sense, bullet.rotation should only change the angle of the bullet, but didn't apply any velocity for it to move. Could you explain how does this work? p.s. Sorry for dumb question here. I am just trying to understand the code. Link to comment Share on other sites More sharing options...
rich Posted December 17, 2013 Share Posted December 17, 2013 Hah! This is one of those rare times when I get to say: read the docs http://gametest.mobi/phaser/docs/Phaser.Physics.Arcade.html#toc27 (specifically the Return value) Link to comment Share on other sites More sharing options...
woratana Posted December 17, 2013 Author Share Posted December 17, 2013 Oh, my bad :/ Thank you for pointing me out the return value I have a little more question on this though,How can radian angle define the speed of the bullet? Link to comment Share on other sites More sharing options...
rich Posted December 17, 2013 Share Posted December 17, 2013 It doesn't. Here this should help clarify it:this.game.physics.moveToObject(bullet, this.player, 500);The above is what makes the bullet move. The moveToObject call sets internal values on the Sprite.body object to get it moving in the right direction. As a by-product of working out where to move to, it knows the angle the bullet ought to face, so it returns it. You don't have to use it though, the above line of code will work just fine on its own. Link to comment Share on other sites More sharing options...
woratana Posted December 17, 2013 Author Share Posted December 17, 2013 Thank you Rich! With this professional level of support, I can see that Phaser would become very well-known in next year Link to comment Share on other sites More sharing options...
Recommended Posts