# Rotate Game Objects Around a Moving Object?

## Recommended Posts

I am attempting to create a series of protective bombs that orbit the player object. So far I have a group of bombs set up and have them orbiting around the player, but would like them to evenly distribute around the player.

``````// within create function

key:'bomb',
frameQuantity: 10
});

// within update function

Phaser.Actions.RotateAroundDistance(this.bombs.getChildren(), {x:this.player.x, y:this.player.y}, 0.02, 150);``````

This works. When the player moves the bomb follows in orbit. But all the bombs are stacked on top of each other. What's the correct way to have them evenly distribute in a circle around the player object? I tried creating a new Phaser.Geom.Circle and then Phaser.Actions.PlaceOnCircle but it seems the bombs cannot be placed on the circle and also rotated?

I am trying to create something similar to this...

but have the group items not eventually collapse into the same location but remain evenly distributed.

##### Share on other sites

I think you're on the right track with PlaceOnCircle, you just have to increment/tween the startAngle and endAngle arguments.

##### Share on other sites

Ah! Ok! I completely missed those optional arguments. Thanks! I also managed to get this working by setting the velocity x and y of each bomb object to match the player velocity everytime the player moves. But seems like not the best solution since it requires mapping over all the bombs each time the player moves in any direction.

##### Share on other sites

Here's the solution I came up with using your suggestion :)

``````// Create

key:'bomb',
frameQuantity: 10
});

this.circle = new Phaser.Geom.Circle(this.player.x, this.player.y, 150);

from: 0,
to: 6.28,
duration: 6000,
repeat: -1
})

from: 6.28,
to: 12.56,
duration: 6000,
repeat: -1
})

// Update

Phaser.Actions.SetXY([this.circle], this.player.x, this.player.y);

Phaser.Actions.PlaceOnCircle(
this.bombs.getChildren(),
this.circle,
this.startAngle.getValue(),
this.endAngle.getValue()
);``````

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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