I have a sprite shooting bullets but the angle that the bullets leave is 90 degrees short of the sprite rotation.I tried adding Math.Pi/2 but it doesnt work. The sprite starts facing up and code of the sprite rotation is this:
Vector2 direction = mousePosition - position;
direction.Normalize();
rotation = (float)Math.Atan2((double)direction.Y,
(double)direction.X) + ((1f * (float)Math.PI) / 2);
The bullet Shoot and Update are the following:
public void UpdateBullets()
{
foreach (Bullets bullet in bullets)
{
bullet.position += bullet.velocity;
if (Vector2.Distance(bullet.position, position) > 500)
bullet.isVisible = false;
}
for (int i = 0; i < bullets.Count; i++)
{
if (!bullets[i].isVisible)
{
bullets.RemoveAt(i);
i--;
}
}
}
public void Shoot()
{
Bullets newBullet = new Bullets(Content.Load<Texture2D>("Sprites/bala"));
newBullet.velocity = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)) * 5f;
newBullet.position = position + newBullet.velocity * 5;
newBullet.isVisible = true;
if (bullets.Count() < 20)
bullets.Add(newBullet);
}