• Content Count

  • Joined

  • Last visited

  1. FlatBeatle

    Angle towards Velocity

    Hi all, I am having a little trouble trying to get my sprite to angle itself towards its current velocity. At the moment the zombies in my game are pointing to the top. They have a random velocity set in the code below. Is it possible to rotate these depending on the direction is it moving? Here is the code I am currently using. The enemies are spawning fine and moving in random directions, just trying to get the lads to rotate to their velocity is a pain. createEnemies: function() { for (var x = 0; x < startingEnemies; x++) { // Create 5 enemies with random positions var enemy = enemies.create(this.game.rnd.integerInRange(50, 1870), this.game.rnd.integerInRange(50, this.game.world.height - 50), 'enemy'); this.game.physics.enable(enemy, Phaser.Physics.ARCADE); enemy.body.velocity.setTo(this.game.rnd.integerInRange(50, 150), this.game.rnd.integerInRange(50, 150)); enemy.body.bounce.set(1); enemy.body.collideWorldBounds = true; var animationZombie = enemy.animations.add('animationZombie'); enemy.animations.play('animationZombie', 30, true); } enemies.x = 100; enemies.y = 50; } I am using Phaser v2.9.2 and the ARCADE physics. This is my first game and post, so let me know if there is any other information you require. Cheers!