How do I make sprites run from player

0 favourites
  • 7 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • I was making a pac-man style game but I don't know how to make baddies run from me! Please help!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • There are a few ways to do this, depending on your situation.

    Do you require pathfinding, or are they free to run straight away from you?

    I'm assuming you already have a system in place to have the baddies run towards you. How are you doing this?

    Try having invisible "flee target" spots around the level. When they need to flee, pathfind to the one closest to them and farthest from the player. Or something along those lines. You'll probably need to add some conditions to ensure they don't flee towards a spot that the player is already along the path to.

    You can use another invisible "avoid zone" around the player for that. When your baddie picks a spot to flee, draw a line between that spot and the baddie to see if it collides with the avoid zone. If it does, that means the player is in the way and it should probably go somewhere else.

    Along the lines of the "avoid zone", you could probably update it as a solid in terms of pathfinding every once in a while, then the baddie using pathfinding definitely won't go there.

  • Programmer3000 I'm looking for the same thing.

    oosyrag I'm using "Set Angle Towards" to make baddies come at the player, but when my player changes into something different I want something like "Set Angle Away".

  • For set angle towards method, that is the easy one. You can use Set Angle Towards player, then set Angle to Self.Angle+180 right after that.

  • Programmer3000 Figured it out. Make your actions "Set Angle Towards(Player.X, Player.Y) then right underneath put "Rotate Clockwise" set at 180.

    Edited to add...

    oosyrag I didn't see your answer. I like your answer better than mine. Thanks!

  • Or better yet : just plain set angle to angle(player.x,player.y,enemy.x,enemy.y)

  • You could create an invisible sprite (I'll pretend it's called "InvisibleSprite") and put it at various points in the map. The more you put in the better because then when you want to get the enemies to run away from the player use an event like this:

    By the way this is for a scenario like pacman, but if it was a bit more open world and you want them to run straight away from you there are much easier ways to do this.

    Also make sure the enemies have pathfinder and give the invisible sprite an instance variable with initial value of 0... I'm going to pretend the instance variable is called "tracking".

    Conditions:

    System -> Every Tick

    Player -> (whatever you use to indicate when the enemies will run away from the player)

    InvisibleSprite -> Pick Nearest/Furthest -> Which: furthest

    X: Player.X

    Y: Player.Y

    Actions:

    InvisibleSprite -> Set Value -> Instance Variable: tracking

    Value: 1

    After this event make another that is like the following:

    Conditions:

    System -> Every Tick

    Player -> (whatever you use to indicate when the enemies will run away from the player)

    Actions

    Enemy -> Find Path -> X: InvisibleSprite.tracking = 1 ? InvisibleSprite.X : Player.X

    Y: InvisibleSprite.tracking = 1 ? InvisibleSprite.Y : Player.Y

    InvisibleSprite -> Set Value -> Instance Variable: tracking

    Value: InvisibleSprite.tracking = 1 ? 0 : Self.tracking

    And finally do one more event like this:

    Conditions:

    Enemy -> On path found

    Actions:

    Enemy -> Move along path

    That should do it, if it doesn't work either reply to this comment or private message me and I'll find another way to do it or figure out where you went wrong.

    -Malcolmtheguy

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)