Cirou Posted June 23, 2014 Share Posted June 23, 2014 Hi all, i'm pretty new to Phaser and yesterday i had a problem with a sprite body rotation. I tried to search on this forum but nothing came out on this. So that's the problem, i have a sprite defined like this: // PLAYER SETTINGS player = game.add.sprite(100, 100, 'player'); game.physics.enable(player, Phaser.Physics.ARCADE); player.scale.setTo(0.4, 0.4); player.body.collideWorldBounds = true; player.animations.add('run', [0, 1], 10, true);And i want it to follow the mouse pointer, and when doing this i want it facing always the pointer direction, so i wrote this: game.physics.arcade.moveToPointer(player, 600); player.angle = game.physics.arcade.angleToPointer(player) - Math.PI / 2; player.animations.play('run');When doing this the sprite moves, play the animation and faces correctly the mouse pointer, but... it's physical body get messed up and the collisions points with walls are wrong. Am I missing something?Sorry for bad english, thanks in advance Link to comment Share on other sites More sharing options...
lewster32 Posted June 23, 2014 Share Posted June 23, 2014 You should be aware that Arcade physics bodies do not and cannot rotate. Add the following to your render state and you can see what your physics body is doing:function render() { game.debug.body(player);} Link to comment Share on other sites More sharing options...
Cirou Posted June 23, 2014 Author Share Posted June 23, 2014 Hi lewster, thanks for your reply!I'm at work now and i can't try the following code but i've found this reading this forum:player.anchor.setTo(0.5, 0.5);Do you think that this could help me? Link to comment Share on other sites More sharing options...
lewster32 Posted June 23, 2014 Share Posted June 23, 2014 Because your collisions are between rectangles, your sprite is going to collide seemingly strangely when it rotates. Setting the anchor won't fix this, but what may help is to reduce the size of the body with body.setSize so that the collision is less obviously happening when the sprite doesn't seem to be touching an edge. Link to comment Share on other sites More sharing options...
Recommended Posts