Line of sight AI all following same target

0 favourites
  • 7 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • I made some animals that are supposed to go towards grass when they see it, then when they hit the grass they gain energy, reproduce and so on.

    It doesn't seem to happen for all of them but once there are a lot of animals most of them get concentrated in one area. After watching for a while I also noticed that if they moved to a different area almost all of them moved and that sometimes animals with no grass around would randomly turn a bit so I'm wondering if the issue has something do with the line of sight

    The code is

    • Animal has LOS to Grass: Animal rotate 5 degrees towards Grass.X, Grass.Y

    Am I doing something wrong?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • cowvsgrass using los

    however picking a grass one needs more conditions the code in capx picks automatic the closest.

  • Well the issue is with multiple "cows" they all seem to move towards the same piece of grass, even when some of them shouldn't be able to see it or at least it seems that way

  • Well the issue is with multiple "cows" they all seem to move towards the same piece of grass, even when some of them shouldn't be able to see it or at least it seems that way

    you have to reduce the LOS distance of view, the example i gave u uses 10,000 pixels.

    a 200 /300 pixels should be more then enough to create a real kind of effect.

    additional each cow would have to check other cows position and see if there are grass spots empty so they can go to them. so that needs to be implemented also as conditions.

  • Ok and how should I go about making them go after the closest patch of grass? Maybe a loop that picks all the grass in a cows line of sight and finds the closest one then the cow moves towards it?

  • One of many solutions.

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

    It is important to have only ONE 'for each' / object. Else you gonna hurt performance.

  • That is amazing, thank you

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