Reputation: 161
Okay, so I've got some code to make my enemies follow the player in my XNA game, but they only follow the player until the player is in front of them. If the player moves past an enemy, it will stop moving towards him. Instead they will continuously move up and down with the player.
The code I've used is this:
Vector2 direction = player.Position - goblins[i].Position;
direction.Normalize();
Vector2 velocity = direction * goblins[i].enemyMoveSpeed;
goblins[i].Position += velocity;
(ignore the goblins bit, I've just replaced the graphics)
Not entirely sure where to go with it, any ideas?
Upvotes: 3
Views: 4970
Reputation: 652
Tom, hello, how are you?
Here you have 2 examples that helped me a lot:
Upvotes: 2