How to make an enemy go after my player?
jblb2424
Member Posts: 65
Hello
In my game I am trying to make a system in which the enemy pursues my player. However, rather than just slapping on a "move to" behavior, my game requires more complex code.
In my game, I have gravity on all of my players through the "acceleration" attribute, so the enemy cannot simply float to to the player using "move to". Also, I have walls and platforms that the enemy needs to go under or jump over depending on where the player is. For example, if the player is on top of a platform, the enemy will jump on to the platfrom, but if the player is under the platform, the enemy will go under the platform to catch the player. The system of the enemy following the player that I need is very similar to using "path nodes" if you are familiar with the term.
How would I go about making such a system? Thanks!
In my game I am trying to make a system in which the enemy pursues my player. However, rather than just slapping on a "move to" behavior, my game requires more complex code.
In my game, I have gravity on all of my players through the "acceleration" attribute, so the enemy cannot simply float to to the player using "move to". Also, I have walls and platforms that the enemy needs to go under or jump over depending on where the player is. For example, if the player is on top of a platform, the enemy will jump on to the platfrom, but if the player is under the platform, the enemy will go under the platform to catch the player. The system of the enemy following the player that I need is very similar to using "path nodes" if you are familiar with the term.
How would I go about making such a system? Thanks!
Comments
Here's one way to do it. First of all, you need the player's X and Y to be global variables. This is vital because all other objects need to access the player's location.
Create objects "Up", "Down", "Left", "right". These objects will be invisible objects placed all over the level that guide the enemy to the player. If the enemy touches these objects, he'll move in that direction. Like if he touches "left" object, he'll move left.
This isn't going to give you what you look for, but it's a good start. Once you get this working, add on more code so it'll adapt to where your protagonist is.
Move to player's X and player's Y.
. . . . hold on demo coming . . .
https://www.mediafire.com/?y4l4i5cactu24rd