Sign in to follow this  
dev578

Moving an enemy to an attack position

Recommended Posts

I am having some trouble getting an enemy to move towards a player so the enemy can attack. This may sound like an unbelievably stupid question, and it is... when the player isn't moving. I then just turn the enemy to face some calculated point where the enemy needs to end up, and then just move it. The problem comes when the player is moving. If I keep trying to sync up the enemies orientation to a continually moving point, the enemy would never get to move within attacking distance of the player. Whats more, this is a networked game. The current way I have my packets set up is that the server will send all clients a packet saying the enemy is either started or stopped moving left, right, down, or up. The enemy can also be told to move, for example, up and right at the same time, which would move it in a circle. This may be the optimal way to get the enemy to the point, but I have no idea how to implement it. The other option, I guess, could be to generate some kind of curve for the enemies movement, but that would be ridiculous because I would have to keep sending a ridiculous amount of packets over the internet toggling the different move states very fast. I may be able to change around the way the networking system works, but I don't even know if that is the way to go or not. I tried finding articles or something on this, but came across nothing. It might just be so trivial that no one has written anything on it, I just keep finding path algorithms, which is not what I want, there currently are no obstacles. I figured I would post this in the math forum, because I think it is more math than AI. I'm not really sure what the solution to this problem is, so sorry If I am wrong. If anyone has any ideas on how this can be done, I would really appreciate it. Thank you Dev578

Share this post


Link to post
Share on other sites
I would do something like this. Lets assume that enemy notices player who is at position (x0,y0). So rotate enemy and move it to (x0,y0). When it reaches (x0,y0) player is at new location (x1,y1). So turn enemy and make it move to (x1,y1) and so on until enemy catches the player. This is the simplest way I can think of. This can be improved by checking player's position more often. Move enemy towards (x0,y0) and after some time (before enemy reaches x0,y0) check if player has moved if yes, then turn enemy and move it towards new position.

If you want to have your enemies a bit smarter you can make them try to intercept the player (with assumption that player does not change its speed and direction).

I hope it helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this