Pathfinding question?

0 favourites
  • 9 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • So I'm trying to design AI for prey.. small creatures you can hunt down. They dont attack, they just run. I want to make a pathfinding event that will make them find a path that is away from the player or other creatures that hunt. If youre chasing them I want them to continue to stay one step ahead of you and be able to adjust their running direction or turn around if you cut them off for example. Any ideas?

  • Depends on how smart you want the preys to be.

    I mean, you could make a basic system where if the player enters a specific zone around them (collision with an invisible rectangle representing the prey's sight or reaching coordinates depending on one or more variables...), they start going the opposite direction. You wouldn't even need pathfinding.

    If you need them to navigate around walls, however, then pathfinding would be the way to go : you could set a bunch of checkpoints for preys, have them look for the farthest one that isn't in the threat's general direction relative to themselves, and have them run for it until the predator's been shaken off.

    Does that help at all? Sorry if I've wasted your time!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Great concepts! They need to navigate around complex maps and areas. Becuase of the size of the game it would be a pain to set checkpoints- though possible I'd rather avoid that approach. I was thinking something more towards the destination being generated randomly (like the idle pathfinding, they find a random destination on the layout to move to) but only places in the direction your character is facing? Perhaps random destinations within in a 90-degree angle from the player's angle? So, in theory, it would have a destination away from the player at all times.

  • So I'm trying to design AI for prey.. small creatures you can hunt down. They dont attack, they just run. I want to make a pathfinding event that will make them find a path that is away from the player or other creatures that hunt. If youre chasing them I want them to continue to stay one step ahead of you and be able to adjust their running direction or turn around if you cut them off for example. Any ideas?

    Have you tried having the prey 'path find' a random X/Y value that is the opposite direction of the player in relation to them? Then it can update either every few seconds if the player is moving or once they reach their destination and they can move again.

    You could also pin an invisible radius sprite to the prey so if the radius object collides with the player it will trigger the prey movement along their path and give them the illusion of smart behavior.

    Not sure if any of this is what you are looking for, just throwing out some ideas .

  • > So I'm trying to design AI for prey.. small creatures you can hunt down. They dont attack, they just run. I want to make a pathfinding event that will make them find a path that is away from the player or other creatures that hunt. If youre chasing them I want them to continue to stay one step ahead of you and be able to adjust their running direction or turn around if you cut them off for example. Any ideas?

    >

    Have you tried having the prey 'path find' a random X/Y value that is the opposite direction of the player in relation to them? Then it can update either every few seconds if the player is moving or once they reach their destination and they can move again.

    You could also pin an invisible radius sprite to the prey so if the radius object collides with the player it will trigger the prey movement along their path and give them the illusion of smart behavior.

    Not sure if any of this is what you are looking for, just throwing out some ideas .

    See I the first idea is what I want to do, I've had the concept for a while but I have no idea how to implement it. I don't know how to specify a random xy within 90 degrees of the player's angle.

  • Hi Uglypenguin,

    Would something like this work for you?:

    https://www.dropbox.com/s/y3le8v60o0kps ... .capx?dl=0

    You can control the hunter with cursor keys, press left mouse to try and hit a prey.

    I've placed a trigger box object (for reacting to the hunter) and a target object (for pathfinding) in a container with each prey to make it easier to see what's going on with the pathfinding behaviour, but you could substitute these for instance variables on the prey if you needed to reduce the object count.

    Toggle prey trigger box and target visibility with the space bar.

    In general it works ok but very occasionally a prey will lock up - haven't figured out why yet.

  • Woah thats amazing! That is exactly what I had in mind. I will have to replicate it in my game. Thank you!

    I also experienced pathfinding locking up completely in some of my other code. Could this be a bug?

  • Uglypenguin

    You're welcome

    There may be an issue with pathfinding breaking if the pathfinder is off-screen - I'm investigating further. For now, I'm switching off the pathfinding in that circumstance using an "Is not on screen" condition .

  • mekonbekon

    If thats the bug and you outrun enemies till they are off screen (thats when I experienced the bug) They wouldn't be able to keep pursuing. I feel that would be comparably un-immersive as them being frozen from the start.

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