# 2-D enemy that orbits a block with variable radii

This topic is 2949 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So, this is one I've been wondering.

You have a block with an enemy that orbits it. I was hoping the radius it is from the block could be variable. The main thing is figuring out just how to re-calculate its positions to provide that circular motion.

It'd seem to me that it would have some set distance from the mid point and then just do a new angle as it goes along and then one would need to use sin/cos in some way to do the new X/Y positions.

Any thoughts? Thanks.

##### Share on other sites
Hi, when you say "orbit", do you mean in a strict physical manner, as a satellite orbiting the earth? Will the enemy be orbiting the block due to gravitational interaction?

cheers,
Mike

##### Share on other sites
I'm not sure what behaviour you are looking for, but calculating the position of the enemy around the block for circular motion is fairly easy:

shipPosition.x = blockPosition.x + cos(angle)*radiusshipPosition.y = blockPosition.y + sin(angle)*radius

Starting with an angle of 0 radians your ship would appear on the right side of the block, increasing the angle over time will make your ship move counter clockwise in circular motion around the block.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 19
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632665
• Total Posts
3007710
• ### Who's Online (See full list)

There are no registered users currently online

×