Degrees in 2D
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.
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)
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement