Making a choice

Is there a way using Logic Bricks to set it up so objects can make a choice. Example, If an object encounters another moving object and has three choices, ( move up, move to the right, move to the left) to avoid a collision. Can this be done using logic bricks? Go into detail or if possible make a simple example so I can see setup.
Thanks

digiman

Yes. Set up a random actuator set to ‘Int Uniform’ with a property like ‘choice’, then set the intervals from 1 to 3. After, set up 3 property sensors with the same property, ‘choice’, and set each one equal to one of the values, and have an actuator attached to each one with whatever you want to trigger- in your case, motions. Hope this helps :slight_smile:


*Make sure your property is an integer.

Since your controller will only activate for an instant, motion values will need to be high. I used this before, and I think ‘5’ worked for what I needed when my constant motion was 0.1, so there is a big difference. However, if you want the object to move indefinitely, then uncheck ‘tap’ mode, or you could have the object go into a new state where each state has its own rules for the object.

  • What are the choices
  • When to chose what choice

Monster makes a good point. I did not explain this in enough detail. I have objects in a small area that move always in a forward direction but are floating in that area. If object “A” comes close to object “B” it will make a choice to move away, but if it moves in a direction it might go through object “C” which might be close by so it has to make yet another choice, so I might need something more than just using a value of 1,2,or 3. That is a problem I can’t solve. I have improved collision detection but not completely.

digiman

I don’t see why this set up wouldn’t work for that either. You could set up another set of “choices” for object “C”. They can both trigger at the same time, so there shouldn’t be any conflict.

Near sensors might be a better option than collision sensors.

It also seems like you need your objects to ‘rotate’ into the new direction, rather than staying at the same orientations. This way they can continue to move forward, ready for the next obstacle.

But, I am having a tough time picturing what you’re describing. Would you be able to upload a blend file or some pictures to help us out?

Yes, it works but still with a problem. My objects all have armatures with the same properties, so when given a choice sometimes they make the wrong choice turn right into each other, want I wanted is to make them never go through each other, if possible for my objects to see each other and make the correct choice. I think that might not be possible.

digiman

This is less an option for a choice. This should be ensured by your logic or the physics engine. See it as “security” for stupid objects ;).

What you are thinking of is a “navigation strategy” (no official term). What does it mean? It means the objects decision where to go (or turn) is purely dependent on the current status (if it sees something or not). This is usually pretty simple to implement and can be used when there is no specific goal (it works with goals too, but it is not necessary).

The opposite is path following. Here the object gets a pre-calculated path that it follows (it knows beforehand where to go). This method is simple too, but the path calculation (path finding) can be tricky. It is pretty useful when there is a specific goal, there is a map to calculate the path on and the map fits the final scenery pretty much.

But back to navigation strategy. There are a lot of ways to implement that. A typical implementation just says: move where you can.

A) can move forward -> move forward else
B) can move left -> turn left continue with A) else

what is the result?
The object will move forward until it finds an obstacle. When it finds one the object will turn. The assumption is that after some turning the object will not detect the obstacle anymore. Then is will move forward until …

According to your example:

“A” will move forward till it detects “B” which is blocking. Then it turn until it does not detect “B”, but now it detects “C” so it continues to turn until it does not detect “B” nor “C”. Then it moves forward.

Okay, exactly how would this implemented with logic Bricks? My objects move randomly and turn away from other objects but if there are a lot of objects in a small area they end up going through each other sooner or later.

digiman

I suggest some sensor objects in front of the object. They can sense obstacles right in front. When they measure something, a decision needs to be made (turning left or whatever) to avoid crashing they can do a full stop (do not need to, but you know … braking sometimes is better than crashing.).

Then the object turns until the forward sensor say … no obstacle … then the object stops turning and moves forward again.

It sounds good in theory but in practice works and sometimes looks like a mess. The objects sense each other and go into a loop lioke they are dancing. I am trying something a bit new right now I have 3 radar sensors on my object, one set to to left, one to the right and one forward. The left turns left the right turns right and the forward is set up like APlich’s hookup. The left is a larger angle than the right. I am trying to make it so when object come close to another object from any angle they should avoid each other smoothly. I am making a sim so I want it to be realistic. I just need to fool with it to make it work like I want. Thanks

Yes, looping is a consequence. This is as the strategy will result in such a behavior.

You could alter the strategy to achieve other effects. For example you can let the object do a random decision between left and right turn. I suggest to throw the dice only when detecting an obstacle once (rather than all the time).

A) can move forward -> move forward else
B) can’t move forward decide if left turn © or right turn (D)
C) turn left look for A)
D) turn right look for A)