Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tutorial? #4

Open
therealrobster opened this issue Sep 21, 2021 · 9 comments
Open

tutorial? #4

therealrobster opened this issue Sep 21, 2021 · 9 comments

Comments

@therealrobster
Copy link

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.

@RodZill4
Copy link
Owner

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.).

@smccourtb
Copy link

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.

@RodZill4
Copy link
Owner

RodZill4 commented Oct 1, 2021

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
Copy link
Owner

RodZill4 commented Oct 1, 2021

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...

@smccourtb
Copy link

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.

@RodZill4
Copy link
Owner

RodZill4 commented Oct 1, 2021

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. ;)

@smccourtb
Copy link

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.

@RodZill4
Copy link
Owner

RodZill4 commented Oct 1, 2021

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

@smccourtb
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants