Sign in to follow this  

Formula for direction ?

This topic is 2847 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

Hello , Im making a top down asteroids game and I cant re-create the formula to turn D degrees (0-360) in to a "percent" (float 0.0 - 1.0) of 180. Or at least I cant get a smooth turning effect [Edited by - jopy on February 27, 2010 8:57:35 AM]

Share this post


Link to post
Share on other sites
It's not at all clear what you're trying to do, actually.

However, your function xlength() returns:

angle value
0 0
90 0.5 * length
179 0.994 * length
180 length
181 -1.006 * length/2
etc.

So there's quite a discontinuity at 180.

Maybe if you let us know what are you trying to do with xlength(), someone can provide more help.

For instance, what do you want to happen at 181?

Share this post


Link to post
Share on other sites
Are you sure you're using sin and cos how you want to be? The cosine of an angle is the distance that you need to move along the x axis to form the base of a right triangle with a hypotenuse of 1 and that angle as the angle between the x axis and the hypotenuse. The sine of the angle is the length of that opposite side, or the y distance. Take a look at the graphs on the side of the wikipedia pages (clicky) to understand whats going on in your functions. Maybe you just have a transformed coordinate system and you do want to be using cos for y and sin for x.

Share this post


Link to post
Share on other sites
If my screen had 0,0 as the lower left corner, and coordinate space increased to the right and top sides of the screen, and my angles were 0 pointing right, PI/2 radians up, PI radians left, and PI*3/2 radians down, my formula for direction would be:

xSpeed = speed*cos(angle)
ySpeed = speed*sin(angle)

And then every frame I would move the objects that amount on that axis. If I wanted 0,0 to be the upper left and the angles to increase in the same direction as before (counter-clockwise) then I just make y:

ySpeed = - speed*sin(angle)

Your language's math library most likely expects radians for angles not degrees.

radians = degrees*PI/180

so 90 degrees = PI/2, etc.

Take a bit to learn this relationship for cos and sin, they're useful and trig comes up quite a bit.

Edit: I can't tell clockwise from counter-clockwise.

[Edited by - DaedalusOwnsYou on February 27, 2010 6:21:58 PM]

Share this post


Link to post
Share on other sites

This topic is 2847 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