Line of sight AI all following same target

Discussion and feedback on Construct 2

Post » Sun Mar 19, 2017 10:24 pm

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?
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Sun Mar 19, 2017 10:33 pm

cowvsgrass using los

however picking a grass one needs more conditions the code in capx picks automatic the closest.
B
75
S
22
G
68
Posts: 1,334
Reputation: 43,265

Post » Sun Mar 19, 2017 11:41 pm

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
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Mon Mar 20, 2017 12:44 am

bbjGames wrote: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.
B
75
S
22
G
68
Posts: 1,334
Reputation: 43,265

Post » Mon Mar 20, 2017 7:56 pm

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?
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Mon Mar 20, 2017 8:09 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Mar 20, 2017 8:34 pm

That is amazing, thank you :)
B
22
S
8
Posts: 203
Reputation: 2,059


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 4 guests

cron