Jump to content

Angle towards Velocity

Recommended Posts

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


Link to post
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...