Jump to content

Sprite angleToPointer issue


Cirou
 Share

Recommended Posts

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...