luxkun / ReGoap

Generic C# GOAP (Goal Oriented Action Planning) library with Unity3d examples
Apache License 2.0
1.02k stars 149 forks source link

Some Rookie questions about it #12

Closed hunterdes closed 7 years ago

hunterdes commented 7 years ago

Hi I am trying to use regoap to implement AI. My example is : my bot is doing patrol until he found his enemy. I have findAction so the precondition: isFindEnemy: false; canMove: true; effect: isFindEnemy: true;

My Question is that where is the best place in findAction I should implement patrol code?

Thanks

luxkun commented 7 years ago

I usually add an "enemyInSight" boolean and an "enemyPosition" Vector3 (only this one can be enough in most of games) in the memory (usually calculated inside a sensor "SightSensor").

So the actions have only to check if that key is equal to a value and do not have to calculate anything.

When the enemy is dead the enemyInSight will be false and so the "killEnemy"/"goToEnemy" actions will fail, or the goal "killEnemyGoal" will fail (since it probably has a check on enemyInSight).

luxkun commented 7 years ago

1) Currently it's not very obvious, since ReGoap use a backward search algorithm, which is way faster than the "globally-implemented" forward search but has few drawbacks such as not knowing previous state (and so position). What you can do is check current agent position and do calculations with that (easier but not good if you have multiple positions change in your plan). Another idea is to check future positions (remember it's going backward, so the actions are "queried" in reverse, from the last to the first) and do calculations with that. What you can do is override GetCost of the generic action "DoSomething", that requires a new position X, using the current goal position (in the FSMExample I am using isAtPosition) and the wanted position X. 2) ReGoapGoalAdvanced supports that, it will warn the agent if the goal is available and not running, the agent will try to run the new goal IF the current goal running has lower priority than the warning one

Reopen this issue if have any additional question!

Djaymare commented 7 years ago

(I deleted this post, so I put it back. Thanks for answering btw)

Hello !

First, thank you for sharing this beautiful piece of code. I'm planning to work with it for a long shot, so I guess I'll have to bother you a lot (in positive ways of course =)) !

I started a little digging and I have some questions :

1- about your exemple, agents gather recipes in the order it's written ; Where would you implement the calculation of the best route (travelling purchaser/salesman problem) ? 2- will a plan stop on priority change or should I manage it ?