Barrerayy Posted April 21, 2016 Share Posted April 21, 2016 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. Link to comment Share on other sites More sharing options...
Barrerayy Posted April 21, 2016 Author Share Posted April 21, 2016 Solved by anchoring the sprites to the middle of the body instead of the default top left. Link to comment Share on other sites More sharing options...
VitaZheltyakov Posted April 21, 2016 Share Posted April 21, 2016 Look it is: http://phaser.io/examples/v2/sprites/pivot Link to comment Share on other sites More sharing options...
Recommended Posts