How to make an enemy go after my player?

Hello :D

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

  • Gordio283Gordio283 Member, PRO Posts: 31
    I never did this with game salad but I've dealt with this on other game making tools programs. You're not going to like the answer...

    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.
  • jblb2424jblb2424 Member Posts: 65
    That is an excellent idea Gordio. I am just stuck on how to alter my code in order to make the enemy move based on where the player is. As of now my enemy simply follows a predetermined path unaffected by the player. Any suggestions?
  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2013
    @jblb2424
    . . . how to alter my code in order to make the enemy move based on where the player is. . . .
    Use the 'Move To' behaviour on the enemy . . .

    Move to player's X and player's Y.


    . . . . hold on demo coming . . .
  • SocksSocks London, UK.Member Posts: 12,822
    Here you go . . . . quick example:

    https://www.mediafire.com/?y4l4i5cactu24rd
Sign In or Register to comment.