-2
\$\begingroup\$

I am making a shoot-em-up with a player-controlled sprite with a gun:

screenshot; player character viewed from above

I have most of the game working, but I have gotten to the point where I need to load in the enemy characters and make them move towards and follow the player.

I know it starts with getting the players position and working out the difference between the player and an enemy, then moving them. I have tried to search the web for this, but they don't really explain it very well and I would rather someone who knows what they are talking about explain it or at least show me how it might work.

\$\endgroup\$
1

2 Answers 2

-1
\$\begingroup\$

Looks like you want to implement stteringbehaviours. Take a look a chapter 3 of this book. I think it would make your game look more natural if you implement it this way.

\$\endgroup\$
1
  • \$\begingroup\$ Why the down vote? \$\endgroup\$ Jun 27, 2015 at 21:26
-1
\$\begingroup\$

if you haven't already gotten this figured out, a simple way to do it without complicated path-finding is to check the position of all of the enemies vs yours. If the enemies are below you position, move them up. If they are too far to the left, move them right. It's as simple as that.

Example:

foreach (Enemy enemy in enemies)
    if(enemy.x > player.x)
        enemy.x -= enemy.speed;
    if(enemy.x < player.x)
        enemy.x += enemy.speed;
    if(enemy.y > player.y)
        enemy.y -= enemy.speed;
    if(enemy.y < player.y)
        enemy.y += enemy.speed;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .