Jump to content
  • Advertisement
Sign in to follow this  
Meagermanx

Degrees in 2D

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

Hey, I'm wondering about the math behind things rotating in a 2D environment. For example, let's say I'm making an asteroids clone, and I want to rotate my ship a bit. I know how to increase its coordinates to move a ship left, right, up, down, ETC, but I don't understand how you can do turning in a pixilated invironment. Can someone explain how this is done, or point me to some tutorials, or something? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Its pretty much the same as in a none pixelated environment.

Your objects can be represented as a vector with an origin.
The origin is your objects location on the screen, and the other end of the vector is the direction the object is facing.

origin = (ox,oy)
pointing = (px, py)

px = sin(angle) * distance from origin + ox
py = cos(angle) * distance from origin + oy


likewise you can move your objects around

ox = ox + sin(angle) * moving_distance
oy = oy + cos(angle) * moving_distance


Because you work in rads, sin and cos are always less than 1, meaning your object will move the amount specified in moving_distance.

Working wioth these vectors, its very simple to start including gravity and inertial physics, (infact these dont need trig functions)






Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!