2-D enemy that orbits a block with variable radii

Started by
1 comment, last by Mussi 13 years, 7 months ago
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.
- Sivak
Advertisement
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
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.

This topic is closed to new replies.

Advertisement