ricardojmendez / UnitySteer

Steering, obstacle avoidance and path following behaviors for the Unity Game Engine
https://numergent.com/tags/unitysteer/
Other
1.2k stars 275 forks source link

UnitySteer and A* pathfinding #36

Closed ilarysid closed 9 years ago

ilarysid commented 9 years ago

Hi, I'm working on my master thesis in Computer Engineering in which I have to simulate a realistic crowd in a city. I'm using UnitySteer with A* Pathfinding (by Aron Granberg), so I created a script similar to SteerForPathSimplified that use a path built with A*. In my scene I have many capsules (agents) which have attached also SteerForNeighbourGroup and SteerForSeparation to avoid themselves (and it works), but if I add an obstacle (with DetectableObject attached) my agents try to avoid the obstacle and not themselves anymore. Why is this happening? Also I have another question: Can I add or remove different streering at runtime (since I need to change the agents' behaviour: for example, initially they are walking through the path, but when it starts a fire they should run away - like SteerForFear helps to do it -)?.

Thank you!

ricardojmendez commented 9 years ago

In my scene I have many capsules (agents) which have attached also SteerForNeighbourGroup and SteerForSeparation to avoid themselves (and it works), but if I add an obstacle (with DetectableObject attached) my agents try to avoid the obstacle and not themselves anymore. Why is this happening?

You mentioned that you added a DetectableObject, but not which behavior you're trying to avoid it with. Could you elaborate?

The forces of all steering behaviors are combined based on their weights. Chances are that what you perceive as them no longer avoiding each other is just the obstacle avoidance behavior returning a stronger force.

Having said that, it sounds like your scenario is better suited for RVOs than for steering behaviors.

Can I add or remove different streering at runtime

Sure you can. It's outside UnitySteer's scope, and more suited for a controlling mechanism like a behavior tree.

ilarysid commented 9 years ago

Seeing your examples, I did an attempt using a capsule as obstacle and SteerForSphericalObstacles attached to my agents (however it should be better to avoid wall or more complex buildings in a different way, but I just tried to reuse your examples to understand the library). Therefore to expect a believable behaviour I have to set various combination of Weight.

Could you explain better about the behavior tree? Because I'm thinking to combine UnitySteer and behaviour trees and my idea is: when it's true the fire condition the agent adopts SteerForFear as steering, when that one is false he executes the idle action (or something else). Am I wrong? I admit it, I haven’t studied the behaviuor tree in depth yet.

ricardojmendez commented 9 years ago

Could you explain better about the behavior tree?

If you're going to add or remove steerings at runtime (or alter their values) you'll need some control mechanism to do it. This can be a script, or a FSM, or a behavior tree. For UnitySteer's purposes it's all the same.

Also, from the Unity side it might be faster if you don't add/remove behaviors, but if you just have them already in the agent and disable/enable them.

ilarysid commented 9 years ago

but if you just have them already in the agent and disable/enable them.

For those classes that extend SteerForNeighbors, if I would disable them I might have to set weight to 0? If I manually enable them or by scripting, they will arise an exception, since they are disabled by SteerForNeighborGroup on Start.

Thank you very much for your help!