I realise there are many questions on this subject. I'm not familiar enough with the geometry or maths to understand the solutions (haven't done maths in a long time), so I'd really appreciate someone helping me to work this out.
I'm trying to move a PictureBox object in C#, with three values: it's start position as a Point coordinate, the angle it is supposed to travel in, and the speed (how many pixels to move).
I tried this method from piecing together different answers:
private Point MoveBullet(Point startPos, float angle, int bulletSpeed)
{
int X = Convert.ToInt32(startPos.X + (bulletSpeed * Math.Cos(angle)));
int Y = Convert.ToInt32(startPos.Y + (bulletSpeed * Math.Sin(angle)));
return new Point(X, Y);
}
However, it only works when the angle is 0. The picture is a tank - when the picture is at the default orientation, with the tank turret facing to the right - the angle is 0. I know that I've probably messed this up by not placing angle 0 at the north, but I'm not sure how to correct the formula according to this rotation.
To illustrate what I mean about the setup, in the screenshot below the angle is 0 - you can see from the label recording the angle. The bullets shoot from the tank correctly - from left to right.
However, when I rotate the tank a bit so that it is facing towards the top-right, the angle is 315 (imagine it's moved 315 degrees clockwise, or 45 degrees anti-clockwise.) I would expect the bullets to fly towards the top-right, but they fly towards the bottom-right. It looks like it's off by about 90 degrees perhaps?
What mistake have I made, and how can I correct the movement formula so that the bullets fly at the expected angle?