How do I make AI that runs away from the player?

0 favourites
  • 13 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • I'm currently making a survival simulation game, and I need help desperately with the AI. I made a thread about this a while ago but I don't think I explained it well enough. I already have a system for the prey to detect the predator (you), but getting the prey to actually run away from the player is a problem. I've uses a method of changing it's angle once it is supposed to run away from me every tick to 180% towards the player and in this same tick -180 degrees away from the player. I also use bullet movement. The ultimate problem I'm having though is that I have no idea how to make it turn away from objects on the layout. Say there is a tree in the way, what do I use for it to detect the tree individually as a single instance, and have it turn away from said object. Walls are also a big problem, as once it turns, say, 90%, it will still be facing the wall or running along it, causing it to glitch. When the prey turns away however, using the system I use (line of sights detection 'collision boxes' and increasing angle clockwise by 90%), It is also at the same time turning away from the player which causes it to not really turn at all and just spaz through entire walls or mountains.

    So, any suggestions on how to make an object 'run away' from the player and detect walls / other objects infront of it, therefore turning it away?

  • Would using pathfinding work for you?

  • Would using pathfinding work for you?

    Not really, as there is no point that I want to direct it to. It's an open world game, and I need it to run away naturally and react accordingly with it's surroundings. No way to pathfind away from an object unfortunately without setting a predetermined point.

  • Yeah.. so you could set a point 500px away from the player at a certain angle, right?

    Wen it's far enough away from the player your prey could go back to idle, or not?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah.. so you could set a point 500px away from the player at a certain angle, right?

    Wen it's far enough away from the player your prey could go back to idle, or not?

    It would probably get it's destination stuck inside an object though, or it would double back and run straight towards you if your in an enclosed areas such as a valley, and the destination is just outside the valley, causing it to just run straight into you to get out of the valley. I guess It could work though, not sure how I would do it?

  • > Yeah.. so you could set a point 500px away from the player at a certain angle, right?

    >

    > Wen it's far enough away from the player your prey could go back to idle, or not?

    >

    It would probably get it's destination stuck inside an object though, or it would double back and run straight towards you if your in an enclosed areas such as a valley, and the destination is just outside the valley, causing it to just run straight into you to get out of the valley. I guess It could work though, not sure how I would do it?

    Basic example

    Now you will have to find a way to move the destination, when it's either overlapping or outside the layout..

  • >

    > > Yeah.. so you could set a point 500px away from the player at a certain angle, right?

    > >

    > > Wen it's far enough away from the player your prey could go back to idle, or not?

    > >

    >

    > It would probably get it's destination stuck inside an object though, or it would double back and run straight towards you if your in an enclosed areas such as a valley, and the destination is just outside the valley, causing it to just run straight into you to get out of the valley. I guess It could work though, not sure how I would do it?

    >

    Basic example

    Now you will have to find a way to move the destination, when it's either overlapping or outside the layout..

    Unfortunately that cap.x is in verion 219, I don't really want to use a beta version as It might mess up my game... :/

  • I'm not sure which part of your game you are worried about, but that's your choice..

    The next stable release will probably be somewhere in january..

  • Well I tried it out, and It's really frustrating to try and understand. Do you have any other method? This creates lots of problems. 1. The destination object isn't binded to any 'prey' so multiple prey will run towards a single one is no others are nearby or something. I don't know, It all doesn't make sense to me, It's giving me a headache. How were multiple objects created to be put ontop of the prey items when there was no event stating to spawn one for each instance of prey and there was only one at the start of the layout. Also, if I were to implement wandering AI, the destination wouldn't change with it and therefore wouldn't be able to run away since It wouldn't be ontop of the destination. Any explanation or other way to do it? I hate the idea of using an object for it to pathfind to because of all these problems. >.<

    I think I'm going to have a migrane from this stupid AI that I'm trying to make.

  • Well I tried it out, and It's really frustrating to try and understand. Do you have any other method? This creates lots of problems. 1. The destination object isn't binded to any 'prey' so multiple prey will run towards a single one is no others are nearby or something. I don't know, It all doesn't make sense to me, It's giving me a headache. How were multiple objects created to be put ontop of the prey items when there was no event stating to spawn one for each instance of prey and there was only one at the start of the layout. Also, if I were to implement wandering AI, the destination wouldn't change with it and therefore wouldn't be able to run away since It wouldn't be ontop of the destination. Any explanation or other way to do it? I hate the idea of using an object for it to pathfind to because of all these problems. >.<

    I think I'm going to have a migrane from this stupid AI that I'm trying to make.

    The destination object is binded to a specific prey, as it's in a container with it..

    If you want the prey to wander inbetween, just pin the object to the prey and unpin it when having to run away..

    You could also use the pin to rotate the prey to prevent overlapping of the destination..

  • Alright, what about when spawning in new prey? If I spawned a destination object with it, how would I make sure it binds to that specific prey instance?

    Sorry, I think I'll look up how containers work first, I've never used them before.

  • It will automatically spawn a new destination, because it is in a container..

    Manual on Containers

  • Thanks, I'll try this method out now. Hopefully I can get over this problem once and for all!

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