X Avoid Y (ai)

0 favourites
  • 2 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • I'm making a life simulation game and I want to have my herbivores avoid the carnivores.

    They have path finding and line of sight? So far my Ai doesn't work 100% of the time, sometimes the fish walk right into the enemy... How can I make it so that sprite X will turn away from sprite Y whenever it encounters its line of sight.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Make sure your Pathfinding Cell border is High (maybe even equal to average Line of Sight?) This way Herbivores will stay readily away from Carnivores naturally as quickly as 1 second once they come into Line of Sight. Carnivores will not mark Herbivores or other Carnivores as Obstacles - therefore they can Path Find right to them.

    Add Sprite Y as an Obstacle for Sprite X (Generally - Animals should always have other animals they wish to avoid as Obstacles in their Pathfinding)

    Be sure to Regenerate the regions of the Pathfinding Grid as objects move (otherwise the Solid objects on the map won't update) - you'll probably want to do this in the most efficient way possible - try taking into account your Sprites Line of Sight and generating a Rectangle that size around your object. Use "Regenerate Region" and do..

    Start X: SpriteX.X - (SpriteX.LineOfSight.Range / 2)

    Start Y: SpriteX.Y - (SpriteX.LineOfSight.Range / 2)

    End X: SpriteX.X - (SpriteX.LineOfSight.Range / 2)

    End Y: SpriteX.Y - (SpriteX.LineOfSight.Range / 2)

    Finally, Every 1 Second & Has Sight of THREAT > Find Path away from Threat

    You may want to make the Pathfinding Cell Size/Border smaller for smoother movement on different animals.. but this will likely require more memory usage as a new Pathfinding grid would have to be generated for each unique size.

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