Skip to main content
gamedev.net
🔒 Locked

Circle Math

Started by hansonc 3 replies 850+ views
Original Post
hansonc
hansonc
Hey, sorry the subject was so indiscriptive i didn't know what to label it. I am programming a simple game found on the creators.xna.com "Getting Started" section. It's the 2D game in case you just jumped over to look it up. It has a cannon that pivots from right to left and is clamped at 90 degrees. With the information given it makes sense how the got that math to work. However, cannonballs are to shoot out of it and they start the cannon balls at the center point of the cannon which to me looks funny if you have fired and then moved the cannon quick, the ball shoots out of the side wall of the cannon instead of appearing out of the muzzle itself. So I sought out to change the origin point of the cannon ball to that just behind the tip of the cannon. But for the life of me I can not figure out what this point is as it's rotating. Is there an algorithm to find this out? Instead of just spitting out random numbers that I think may correlate to it, please just ask me questions and i'll be happy to provide as much info as i know :) Thank you!
h4tt3n
h4tt3n
Not knowing any details on how the game is constructed...

ball_spawn_position_x = cannon_position + (barrel_length - ball_radius) * cos(barrel_angle)

ball_spawn_position_Y = cannon_position + (barrel_length - ball_radius) * sin(barrel_angle)

or something very similar.

cheers,
Mike
hansonc
hansonc
Mike,

Thank you for responding. The equation you gave is the equation that I have applied however it causes the (test cannonball) to rotate in an eliptical instead of following the barrel tip path.

Cheers!

Chris
anemian
anemian
A circle is just plotted cordiants of both SINE and COSINE. One as the X and the other as the Y.
The only valid measurement of code quality: WTFs/minute
h4tt3n
h4tt3n
Could you post the relevant code for us to look at?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.