Basically, I have a function that has a spaceship follow the mouse pointer, which works perfectly.
void lookAtMouse(sf::RenderWindow &app)
{
sf::Vector2f curPos = sprite.getPosition();
sf::Vector2i position = sf::Mouse::getPosition(app);
const float PI = 3.14159265;
float dX = curPos.x - position.x;
float dY = curPos.y - position.y;
float rotation = (atan2(dY, dX)) * 180 / PI;
sprite.setRotation(rotation - 180);
}
I've tried to modify this to work for the projectiles it shoots, however it doesn't work and causes all kinds of graphical glitches, which I think I know why.
void MoveBullet(int numOfBullets)
{
for (int i = 0; i < numOfBullets; i++)
{
sf::Vector2f curPos = bullet[i].getPosition();
sf::Vector2i position = sf::Mouse::getPosition(app.window);
const float PI = 3.14159265;
float dX = curPos.x - position.x;
float dY = curPos.y - position.y;
float rotation = (atan2(dY, dX)) * 180 / PI;
if (bullet[i].exists) bullet[i].Move(dX, dY);
}
}
How would I approach having the projectiles fire to wherever the mouse pointer is? I can provide full source if required.