jaymeh Posted July 17, 2014 Share Posted July 17, 2014 Hi All, Was wondering if someone could help, I have just started using phaser a few weeks ago and have been relying heavily on the tanks example to try and build my own game. Currently I am having an issue with some code which is supposed to fire a bullet where the rotation of the bullet is off by 90 degrees.// Setup a group for player bulletsgBullets = game.add.group();gBullets.enableBody = true;game.physics.arcade.enable(gBullets);gBullets.createMultiple(30, 'playerBullet', 0, false);gBullets.setAll('anchor.x', 0.5);gBullets.setAll('anchor.y', 0.5);gBullets.setAll('outOfBoundsKill', true);gBullets.setAll('checkWorldBounds', true);cSpacebar.onDown.add(this.fireBullet, this);fireBullet: function() { // Create a bullet element using players position; var bullet = gBullets.getFirstExists(false); bullet.reset(this.player.x, this.player.y); bullet.rotation = game.physics.arcade.accelerateToXY(bullet, this.player.x, this.player.y -10, 200, 200, 200);}Here is an example image of what is happening. I am wanting the sprites to be rotated vertically. I tried to rotate the sprite through the image but this however is strangely causing the same issue. Any help would be greatly appreciated. Thanks,Jaymeh Link to comment Share on other sites More sharing options...
lewster32 Posted July 17, 2014 Share Posted July 17, 2014 I think this is because your sprites are not oriented correctly in the first place. The default orientation in Phaser is facing to the right, so sprites should be drawn facing that way initially. If you just want to fix the rotation you could do this:bullet.rotation = game.physics.arcade.accelerateToXY(bullet, this.player.x, this.player.y -10, 200, 200, 200);// add a quarter turn to the rotation (a full turn is pi * 2, so a quarter turn is pi / 2 or pi * 0.5)bullet.rotation += Math.PI * 0.5; Link to comment Share on other sites More sharing options...
jaymeh Posted July 19, 2014 Author Share Posted July 19, 2014 Perfect, just the answer I was looking for. Thanks for your help. lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts