How do I make an enemy speed up when he spots the player?

0 favourites
  • 4 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Hey. Been trying to figure this one out for a while, but I'm stumped. I can get the enemy to speed up when he sees the player, but I can't get him to resume his normal speed when they player gets outta his view. I didn't like using the line of sight function 'cause, from what I understand, it's a circle around the enemy, so he's gonna spot the player even with his back turned.

    Can anyone help?

    Here's how I have it set up. I'm probably going the wrong way about this, but I'm making this up as I go.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • first, comment your code.. this is not easy to look at.. you'll be doing yourself a favor when you don't look at it for a few months and return to it.

    that Wait could be a problem since it's executing the wait and in that time the player might move out of range and then the max is then set to 130.

    I would think about using distance() instead of X +/- might be easier to do.

    sidenote: you should do less than or equal to 100, since the way you have it, the value 100 is not being represented at all. Your character is probably moving all over the place but technically you might want to cover 100. If some how the distance is 100 and player and sluggo are stationary.. no code will be executed.

  • easy. if it's using pathfinding and los:

    condition - Los has view towards playerObject

    action - set pathfinding maxspeed +50 (from current, can be 0), and also remember to set acceleration to some number like 1000 or so (so your object will speed up to current +50(or however much you set))

    - regen obstacle map

    - find path to playerObjectX, playerObjectY

    - on path found (condition)

    - move along path

    though this will repeat itself each tick it might be hard on your CPU because of regenerating obstacle maps and stuff, so i recommend putting in first condition a "each 0.2 sec" - instead of each 0.017ms this is each 0.200 ms so it will burden your cpu less.

    also you could pull regenerate obstacle map outside of this event if you have a static map

  • Thanks, guys. I'll give it a go.

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