Jump to content

accelerationFromRotation isn't moving a sprite in the right direction


Recommended Posts

Hey everyone, I am having an issue with accelerationFromRotation sending my player in the wrong direction. I'm setting it up so that the player will be spinning using angularVelocity and when you press space it moves in the direction that it's currently facing. To do that I'm using accelerationFromRotation to get a point then using moveToXY to push them in that direction. This definitely works some of the time, but most of the time it send the player in a seemingly random direction, so I think I'm missing something about how this is meant to work. Could someone enlighten me?

Edit: I should add that I know moveToXY will try to move the whole way to the end of the point object which is beyond the screen, so I'm using drag to slow it down so that it is just a shove rather than a fling to the distance

This is the function I'm using to move the player:


function shunt() {
        playerRotate = false;//so we know the player isn't spinning while they move
        player.body.angularVelocity = 0; //actually stopping the spinning

        var goTo = game.physics.arcade.accelerationFromRotation(player.previousRotation, 300, player.body.acceleration);//to make the point to move towards

        game.time.events.add(Phaser.Timer.SECOND / 2, slooooow, this); //wait half a second then start rotation again

        game.physics.arcade.moveToXY(player, goTo.x, goTo.y, 600);  //move the player towards the point

        function slooooow() {
            playerRotate = true;



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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