Jump to content

Arcade sprite.angle not moving the body


Barrerayy
 Share

Recommended Posts

I'm really not good at explaining this but here it goes, added pictures to better demonstrate the issue.

I've created some enemies that once the player gets in a certain range accelerate towards the angle between them and the player. This works fine but results in enemies not actually rotating based on the direction they move in. This can be seen in picture 1. If i set the angle of the sprite using atan2 the sprites rotate as they should however the body stays at the same location as before and the sprite rotates around the top left corner of the body. This can be seen in picture 2

Here is the function that moves the enemies

function rusherTrackPlayer()
{
    for (var i = 0; i < rushers.children.length; i++) {
        rusher = rushers.children[i];
        if(Phaser.Math.distance(player.x, player.y, rusher.x, rusher.y) <= 2000) {
            game.physics.arcade.accelerationFromRotation(game.physics.arcade.angleBetween(rusher, player), 400, rusher.body.acceleration);
            rusher.body.maxVelocity.x =  400;
            rusher.body.maxVelocity.y = 400;
            rusher.angle = Math.atan2(rusher.body.velocity.y, rusher.body.velocity.x)  * (180/Math.PI) + 90;
        }
    }
}

So my issue is how to get the body to align with the angle of the sprite. I believe i can make the sprite rotate around the middle point of the body instead of the top left corner but I haven't figured out how to do it yet.

Picture1.png

Picture2.png

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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