Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Make an object spin to face another one  (Read 1853 times)

0 Members and 1 Guest are viewing this topic.

AdrianHEY

  • Newbie
  • *
  • Posts: 14
    • View Profile
Make an object spin to face another one
« on: April 15, 2021, 07:50:46 pm »
I am trying to make the enemies face the player and I dont know what to do. I've tried this code but it didn't work:
 
void enemyRotatePlayer(sf::Sprite player) {
                float angle = atan2(player.getPosition().y - enemy.getPosition().y, player.getPosition().x - enemy.getPosition().x) * 180 / 3.141;
                enemy.setRotation(angle);
        }
« Last Edit: April 16, 2021, 09:30:39 am by AdrianHEY »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: Make an object spin to face another one
« Reply #1 on: April 15, 2021, 10:28:39 pm »
'it didn't work' means it didn't compile?
Visit my game site (and hopefully help funding it? )
Website | IndieDB

 

anything