1
General / Re: Rotate against sprite
« on: March 22, 2016, 12:04:16 am »
I am currently using this code:
But I don't think I should have to add the -90. Also how should I fix the bullets. As I am shooting and the enemy is moving up, it does not hit the enemy
Code: [Select]
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("Bullet", new Bullet(this->map, this->getPosition().x, this->getPosition().y, degrees, 500));
}
But I don't think I should have to add the -90. Also how should I fix the bullets. As I am shooting and the enemy is moving up, it does not hit the enemy