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

Author Topic: TDS Shooter Enemy Programming issues  (Read 2916 times)

0 Members and 1 Guest are viewing this topic.

snowf1ake

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
TDS Shooter Enemy Programming issues
« on: December 15, 2017, 06:28:09 am »
Hi. I've got an idea of creating a mini-shooter with a top-down perspective.

Everything went smoothly till i came to the enemy programming. I wanted the enemies to move towards the player, and i knew in theory how i am to do it. I used this piece of code in order to determine the direction at which the enemy will chase the player.

float m_angle = atan2(target.getPosition().y - enemy.getPosition().y, target.getPosition().x - enemy.getPosition().x);
        sf::Vector2f direction(std::cos(m_angle), std::sin(m_angle));

        enemy.move(direction * 190.f * deltatime);
 

I placed it into the enemy::update function- same function where the window.draw(enemy); was. Although it worked, and the enemy was chasing the player around the map, it has shown different results when i had several enemies. I made a scene where 7 enemies were supposed to chase the player. And they did, in fact. However, while running towards him, the enemies all took the same position and were like in each other. So instead of 7 circles chasing my player, i saw 1 circle that included all those 7( screenshots provided ).

As it can be seen at screenshot 1, in the beginning, all seven circles are separate. However, after a short chase, they come to the same position and start moving synchronically. How do i make it look like a normal chase, without my circles coming into one-another(keep distance)?

Thanks in advance.

achpile

  • Full Member
  • ***
  • Posts: 231
    • View Profile
    • Achpile's homepage
    • Email
Re: TDS Shooter Enemy Programming issues
« Reply #1 on: December 15, 2017, 07:37:47 am »
just make them not to overlap. use collision detection etc.

snowf1ake

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: TDS Shooter Enemy Programming issues
« Reply #2 on: December 15, 2017, 11:00:34 pm »
But they will still form a row of stupid shooting targets, wont they?


Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: TDS Shooter Enemy Programming issues
« Reply #4 on: December 15, 2017, 11:32:13 pm »
To expand on fallahn's answer a bit, the best solution depends on what kind of game you are making and how smart the enemies should be. If you don't want your enemies to end up in a line then you will need to implement something a little more advanced than just taking the direct angle towards the player.

For example, if you need your enemies to be kind of dumb (zombies?) then you can just give them a random "reaction delay" such that they don't react instantly to a player's position. Different enemies can have different delays so that they don't end up all moving together. Or maybe they don't take the perfect angle towards the player.

If you need your enemies to be smart you can try to predict where the player is moving to and try to cut them off. Or, as fallahn mentioned, you can try to implement a more advanced "flocking" behavior for your group of enemies.

You can google these terms and probably find good resources on how to implement different types of moving AIs. These aren't really SFML related questions, so you may not get very detailed help here.

snowf1ake

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: TDS Shooter Enemy Programming issues
« Reply #5 on: December 16, 2017, 02:39:17 am »
Thanks very much, i was starting to believe that i will never get a good fat answer :)

 

anything