AI cars spawning on same layer, won't detect each other

Get help using Construct 2

Post » Tue Sep 26, 2017 7:05 pm

Hi folks! I got a problem that i really don't know how to solve it. Can you help me please? AI cars that are on the same layer, won't detect each other. I tried to use the L.O.S behaviour, so each AI car would know each other and would avoid crashing one into another, but this won't work. I'm saying that because when i use the L.O.S behaviour in the AI cars to detect the player that is in another layer above, it works 100%. What can i do to fix this? Thank you!!!
B
7
S
3
G
3
Posts: 19
Reputation: 2,109

Post » Tue Sep 26, 2017 7:39 pm

Probably some issue with picking, probably picking itself since a car is trying to detect a car. When the car is detecting if it is in sight of the player the picking logic is much easier, to determine whether a car can see a car you may have to add in some variables or IDs to ensure that it is not picking itself and that it is not applying the logic to all cars when one is in LOS.
B
53
S
21
G
95
Posts: 2,453
Reputation: 56,121

Post » Tue Sep 26, 2017 8:23 pm

plinkie wrote:Probably some issue with picking, probably picking itself since a car is trying to detect a car. When the car is detecting if it is in sight of the player the picking logic is much easier, to determine whether a car can see a car you may have to add in some variables or IDs to ensure that it is not picking itself and that it is not applying the logic to all cars when one is in LOS.



Hey! In my game, there''s a family where all the cars are in it. And i'm using a code tat spawn randon cars on street from the same family. And that's why i'm using the code ''from car to car from the same type'' and etc. But thank you man, i'll try to create something that makes sense.
B
7
S
3
G
3
Posts: 19
Reputation: 2,109

Post » Wed Sep 27, 2017 12:50 pm

Maybe a screenshot of the events where you do the detection could help to understand your problem. It can depend on how you built your game. For example, it seems each car is a different object type from what you are saying, and that you collected them in a family. If so, then the picking should be a double condition, car in line of sight of car, car.UID =/= self.UID

It's hard to know where you made your error. What is sure though, is that an object can detect another object on the same layer, this has no reason to interfeer.

You say you detect the player's car correctly, but it's another object type, so the logic may not be in the same event (it shouldn't be at least). So yeah, a screen cap maybe ? ^^ or a sample capx where you can reproduce the same behaviour with the fewer objects possible, a unit-test around your problem, will help us help you
B
17
S
9
G
4
Posts: 473
Reputation: 6,341

Post » Wed Sep 27, 2017 5:26 pm

Guizmus wrote:Maybe a screenshot of the events where you do the detection could help to understand your problem. It can depend on how you built your game. For example, it seems each car is a different object type from what you are saying, and that you collected them in a family. If so, then the picking should be a double condition, car in line of sight of car, car.UID =/= self.UID

It's hard to know where you made your error. What is sure though, is that an object can detect another object on the same layer, this has no reason to interfeer.

You say you detect the player's car correctly, but it's another object type, so the logic may not be in the same event (it shouldn't be at least). So yeah, a screen cap maybe ? ^^ or a sample capx where you can reproduce the same behaviour with the fewer objects possible, a unit-test around your problem, will help us help you




Hi! But the cars are the same objects in the family group. That's why maybe i'm not doing the things right. I created a mini city to test the AI cars spawning on streets and try to make them detect each other. In this layout, i just have one single type of vehicle. Then i copies and pasted some of them. And the codes make them drive on street randomly. I'm know that, the code to pick the nearest car and compare it's distance between the (AI car) that is behind, we use the following:[b][b] ''SISTEM> COMPARE TWO VALUES> if distance(car.x,car.y,car.x,car.y)> then.... (what to do)... '' [/b][/b]And we should set to the 'family group'' a variable with a name like: ''carfamily.id''. And in it, we will save what's is the UID of the nearest (AI car) that is in Line of Sight of the AI car that is coming from behind. But i really don't know how to create this system right. I guess i inserted wrong number or even all this code i wrote above is wrong. And just to let it clear, i really don't know how to use the ''UID'' AS A id of a object properly. It get worst for me now, because we're talking about of an object that will have to detect the same object as itself. Sorry if my english is not so good and i would aprecciate if you correct me. I'll let a print screen of my scheme below.
The cars that are the same object, has the following things enabled:

- Colisions on
- Line of Sight: 180° Range: 200 distance

1- http://i67.tinypic.com/fabwnm.png

2-http://i65.tinypic.com/2zhecrp.png
B
7
S
3
G
3
Posts: 19
Reputation: 2,109

Post » Wed Sep 27, 2017 6:10 pm

First of all, thanks for this detail. You even color coded your explanations, it was very nice :)

If there is only 1 type of car object, the family is useless. Using multiple instances of the same object type is normal and doesn't require a family. A family would be useful for having cars, trucks, and other vehicle types that share some properties, but may differ in some points. That doesn't change your problem, but I thought I'd say it just in case.

Your problem here seems to be the selection of both cars, yep.
The LoS detection will need a loop on each car that you want to analyse, so a "For each car" or "For each Vehicule_Group". You will also want to filter the cars, to only check cars that need checking. For example, a test on the "car_ID" variable you want to set.
Once you do that, even without the check on the variable, all your cars should stop when they first see another car, so your game should stop quite fast.

Second problem will be to set the variable correctly, to be able to have 2 different entities in the action. The easiest way is to create a new family containing all the vehicles from the first family, but with nothing else. This family is only here for being able to manipulate both vehicles independently. Let's call this new Family "LoS_Target".
So at this point, the trigger of your action should be :
  • For Each Vehicle_Group
  • Vehicle_Group.car_ID = 0 // so if we already set the variable, we don't do the detection action again
  • Vehicle_Group Has LoS to LoS_Target
I'll add some propositions to that :
  • LoS_Target.UID < Vehicle_Group.UID // this will prevent that 2 vehicle check each other. The first will check the second, but not the other way. It depends on what you want to do but it can be useful sometimes
  • Vehicle_Group.UID =/= LoS_Target.UID // this is redondant if you did use my first proposition, but is essential if not, as it will prevent a car from detecting itself. I'm not sure if this is integrated in the behavior by default, so I always add it to be sure.
Now, in the action, we can manipulate both objects as we wish. For example :
  • Vehicle_Group.car_ID = LoS_Target.UID // we set the variable as you described.
  • Vehicle_Group.AI_var_SPEED = LoS_Target.Car.Speed // or something close to that, I didn't reproduce your code

Be aware that LoS check are costly if done too much, don't overdo it if useless.
B
17
S
9
G
4
Posts: 473
Reputation: 6,341

Post » Wed Sep 27, 2017 10:07 pm

Guizmus wrote:First of all, thanks for this detail. You even color coded your explanations, it was very nice :)

If there is only 1 type of car object, the family is useless. Using multiple instances of the same object type is normal and doesn't require a family. A family would be useful for having cars, trucks, and other vehicle types that share some properties, but may differ in some points. That doesn't change your problem, but I thought I'd say it just in case.

Your problem here seems to be the selection of both cars, yep.
The LoS detection will need a loop on each car that you want to analyse, so a "For each car" or "For each Vehicule_Group". You will also want to filter the cars, to only check cars that need checking. For example, a test on the "car_ID" variable you want to set.
Once you do that, even without the check on the variable, all your cars should stop when they first see another car, so your game should stop quite fast.

Second problem will be to set the variable correctly, to be able to have 2 different entities in the action. The easiest way is to create a new family containing all the vehicles from the first family, but with nothing else. This family is only here for being able to manipulate both vehicles independently. Let's call this new Family "LoS_Target".
So at this point, the trigger of your action should be :
  • For Each Vehicle_Group
  • Vehicle_Group.car_ID = 0 // so if we already set the variable, we don't do the detection action again
  • Vehicle_Group Has LoS to LoS_Target
I'll add some propositions to that :
  • LoS_Target.UID < Vehicle_Group.UID // this will prevent that 2 vehicle check each other. The first will check the second, but not the other way. It depends on what you want to do but it can be useful sometimes
  • Vehicle_Group.UID =/= LoS_Target.UID // this is redondant if you did use my first proposition, but is essential if not, as it will prevent a car from detecting itself. I'm not sure if this is integrated in the behavior by default, so I always add it to be sure.
Now, in the action, we can manipulate both objects as we wish. For example :
  • Vehicle_Group.car_ID = LoS_Target.UID // we set the variable as you described.
  • Vehicle_Group.AI_var_SPEED = LoS_Target.Car.Speed // or something close to that, I didn't reproduce your code

Be aware that LoS check are costly if done too much, don't overdo it if useless.




Thanks for your patience to read everything and help me again. And i'm very happy that you understood what i meant. For me, is not so easy because what i want as you saw, it's very specific details. There's a lot of tutorials out there, but 1% explains exactly what we want. Thanks to you and another users, i'm progressing well in this. I'll try to do everything again and see what will going to happen. Bye! :)
B
7
S
3
G
3
Posts: 19
Reputation: 2,109


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests