Sign in to follow this  

2-D enemy that orbits a block with variable radii

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

If you intended to correct an error in the post then please contact us.

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 this post


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


Link to post
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)*radius
shipPosition.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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this