godot-goap icon indicating copy to clipboard operation
godot-goap copied to clipboard

tutorial?

Open therealrobster opened this issue 3 years ago • 9 comments

Hi there,

I'm not at the level to fully understand this by reading the code. Is there any chance a quick overview of the code and what it's doing? Maybe even just dialog as you browse over the relevant code so I can consider what that's doing and then implement it into my game? Thank you and I really look forward to understanding this further.

therealrobster avatar Sep 21 '21 05:09 therealrobster

The only function you need to understand for using that addon is the "goap" function in player.gd in the example. That function reevaluates the goap algorithm whenever necessary to define the list of actions to be taken. Everything else in this file defines the actions themselves (running, picking up objects etc.).

RodZill4 avatar Sep 26 '21 11:09 RodZill4

This probably isn't the place for it but I'm having the same issue. I'm incorporating it into my 2d project and the plan() function is not returning a plan so it dies there just idling. How are goals determined? I set mine to cut_tree as I just want him to simply cut a tree for testing purposes. A breakdown would be useful. Mine seems to be getting lost in the astar function. Yours iterates a few times but mine only iterates twice i believe. I have one action under action planner: cut_wood.

smccourtb avatar Oct 01 '21 16:10 smccourtb

This probably isn't the place for it but I'm having the same issue. I'm incorporating it into my 2d project and the plan() function is not returning a plan so it dies there just idling. How are goals determined? I set mine to cut_tree as I just want him to simply cut a tree for testing purposes. A breakdown would be useful. Mine seems to be getting lost in the astar function. Yours iterates a few times but mine only iterates twice i believe. I have one action under action planner: cut_wood.

OK, could you share your project or at least give me more details? You have only one action, but what are its preconditions and effect?

Preconditions and effects describe how the "status of the world" changes. For your very simple example, you could say the status has 2 properties:

  • player_sees_a_tree
  • player_sees_wood

Your "cut_wood" action would have "player_sees_a_tree" as precondition, and "player_sees_wood" as effect.

To use GOAP, you have to:

  • "calculate" the current status (detect trees around the player): that's what the get_goap_current_state() function does in the example
  • create the "goal". This could always be "player_sees_wood" in your example, so the character will cut trees forever, but the project example has a goal that depends on the status (planting trees if necessary, then chopping them, and never be hungry)
  • call the "plan" function with the status and the goal as parameters, and it will return the list of actions.
  • then perform those actions in order. And when the list is empty, or when an action fails, repeat from start.

Hope this helps!

RodZill4 avatar Oct 01 '21 17:10 RodZill4

BTW, when selecting the ActionPlanner node, there is an editor in the bottop panel. I never coded the "simulation" part, but the editor should work... Maybe I should fix that...

RodZill4 avatar Oct 01 '21 17:10 RodZill4

here's my project: https://github.com/smccourtb/lore-torn i haven't implemented any movement and took out your physics process function to figure out how it all works. I guess I'm having a hard time following it.

are goals only established in the goap_get_current_goal() function? I'm sure when i can get the plan to return I can get a better idea on how the actions are implemented. I'm just stuck there as of right now. currently debugging yours and stepping through with breakpoints to figure out where ours diverge. Maybe i need a wait action like yours? I appreciate the time you're taking to explain.

smccourtb avatar Oct 01 '21 17:10 smccourtb

You don't have to debug or understand the plan function, it works. :D Just give it actions, a start state, and goals, and it will generate plans for you. ;)

RodZill4 avatar Oct 01 '21 19:10 RodZill4

so it works if i set the goal to "sees_tree" *i think". at least if calls the use_nearest_object_function(). but if the goal is set to 'cut_tree' it does not. Seems wrong because my goal is to cut the tree down, not just see a tree. seems opposite to me.

smccourtb avatar Oct 01 '21 19:10 smccourtb

Just looked at your project. The goal should be sees_wood. sees_tree is the initial status.

RodZill4 avatar Oct 01 '21 19:10 RodZill4

I just realized that. so the goal has to be part of some actions effects? is that correct?

smccourtb avatar Oct 01 '21 19:10 smccourtb