Rotate towards enemy

Hi, I am making a tower defence game. I am moving the enemy, and rotating the tower. If I push space the tower shoots. I am trying to calculate where the bullet should hit the enemy, and I am wondering how I can do this. This is what i currently got:

1
2
3
4
5
6
7
8
9
10
11
12
enemy->setOrigin(enemy->getGlobalBounds().width / 2, enemy->getGlobalBounds().height / 2);

	float degrees = atan2(this->getPosition().y - enemy->getPosition().y, this->getPosition().x - enemy->getPosition().x) * 180 / PI;
	degrees -= 90;

	this->setRotation(degrees);

	degrees -= 90;

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Space) && !this->spaceKey){
		this->entityManager->Add("pBullet", new Bullet(this->map, this->getPosition().x, this->getPosition().y, degrees, 500));
	}
Last edited on
Topic archived. No new replies allowed.