1

I'm busy with a little topdown shooter in XNA. Now I have a little Mathematical problem: I have a sprite, a human that's holding a 9mm. Now the sprite looks at the mouse cursor. When I shoot, I want to show a little muzzle flash @ the end of the gun barrel. However, the coordinates of the end of the barrel will change when you rotate the character.

How can I get the correct coordinates in a sprite that is the end of the barrel when for example the end of the barrel is 14px above a players head?(topdown)

So basicly I need to know how to get coordinates of a certain point in a circle that has an certain angle with the orgin.

Thanks!

4

```
x=orig.x+cos(alpha)*r;
y=orig.y+sin(alpha)*r;
```

Where alpha is the angle between the x axis and the line extending the barrel; r is the radius of the circle (the lenght of the barrel).

One or both of the `+`

s might have to be replaced with '-', depending on the orientation of the coordinate system (or play around with adding multiples of 90 degrees (up to 270) to alpha until you get it right).

If the muzzle flash is directional you need to set it's origin to be at its back center and apply the same rotation you did to the human sprite - Murtnowski 2012-04-03 21:12

That did the job! Thanks - Basaa 2012-04-03 21:15