float x1 = shot_offset_x; //Move triangle to origin before rotation float y1 = shot_offset_y; float cos = (float)Math.Cos(p.getDirection()); //Based on player direction. float sin = (float)Math.Sin(p.getDirection()); x1 = x1 * cos + y1 * sin; //Rotating x1 and y1 about point 0,0? y1 = y1 * cos - x1 * sin; x1 += p.X; //Move triangle back to player position y1 += p.Y;
The bullets created are always near the player but never in the correct position. They seem to be rotating around a point near the player but not at his origin. Can anyone show me where I went wrong?
Edit: I seem to be getting closer here. I'm working with the following code now:
Vector2 point = new Vector2(shot_offset_x,shot_offset_y); point = MathTool.rotatePoint(point,p.getDirection()); point.X += p.X; point.Y += p.Y;
public static Vector2 rotatePoint(Vector2 point, float angle)
{
float cos = (float)Math.Cos(angle);
float sin = (float)Math.Sin(angle);
point.X = point.X * cos - point.Y * sin;
point.Y = point.Y * cos + point.X * sin;
return point;
}
This seems to want to work, but instead of the circle one would expect its making a figure eight shape. Is there still something I'm doing wrong?


















