X Avoid Y (ai)

Get help using Construct 2

Post » Tue Sep 08, 2015 8:23 pm

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.
B
7
S
1
Posts: 6
Reputation: 1,641

Post » Tue Sep 08, 2015 10:23 pm

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.
B
78
S
25
G
9
Posts: 85
Reputation: 9,255


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, brunopalermo and 18 guests