2D game math help

Hi I'm currently making a 2D game and I'm struggling on how to implement bullets for my object to fire. I have seen that this is the math/piece of code that allows the bullet to travel in a straight line.

1
2
		bulletPositions.at(i)->X += 2.0f*(cos(bulletRotations.at(i)*3.14159265 / 180));
		bulletPositions.at(i)->Y += 2.0f*(sin(bulletRotations.at(i)*3.14159265 / 180));


Now I've got it to work and it's firing bullets but the direction of the bullets are wrong and I believe that maybe the algorithm is wrong, or something in my code is wrong.

I have a hunch it's to do with my rotation system of my sprites (THEY ARE OFFSET BY 90 DEGREES)

Could this offset be why they are not travelling in the correct direction? For example, 90 degrees should be turning to the right (EAST) but it's actually facing (WEST). 270 degrees should be facing WEST and it's actually facing EAST.

North and South are the same, 360/0 is NORTH and 180 is south.

How can I implement this change into the algorithm to correct the path that the bullets take? Thanks!

Simply, the circle is flipped and goes anti-clockwise in order to increase the rotation and I think that's why it's confused :)

http://oi59.tinypic.com/264gtmo.jpg


Further testing solved my problem and as it's inverted, I had to swap the calculations too.
1
2
		bulletPositions.at(i)->X -= 2.0f*(sin(bulletRotations.at(i)*3.14159265 / 180));
		bulletPositions.at(i)->Y -= 2.0f*(cos(bulletRotations.at(i)*3.14159265 / 180));


Last edited on
Topic archived. No new replies allowed.