I am trying to create a GOAP AI in the Unity engine. I have done MANY searches but haven’t been able to learn it, so please don’t send any links to videos or websites. That said, I have an example that might be easier for me to understand:
(The first test I want to do is create an NPC whose goal is to eat an apple, but I can also create a box that contains an apple. The apple can be consumed as soon as it is obtained, but the one inside the box needs to be taken to a table (“table” is an object that I would place in the scene).
My project is 2D, don’t use any third-party plugins/assets, and please add plenty of comments to the code or explain in the response you send.
If your goal is specifically to implement GOAP, first describe to yourself exactly what that is, what the parts are and what final result you would consider a successful implementation.
Once you have done, that move forward with the smallest steps. Obviously at least you would need an NPC and an apple to start, as well as some relevant game context for them to live in, move around in, and of course detect each other’s presence.
100% of those parts are necessary prerequisites before you can even consider making any sort of planning or behavior. Until you have that, you can’t move forward any further, so start there.
If you don’t do that, I guarantee you that nobody here is going to do that for you in this little box!
Basically, work like this guy:
Imphenzia: How Did I Learn To Make Games:
It’s quite a broad topic, and probably a little bit too much to cover everything in a forum post.
To help you out:
- GOAP basically using a STRIPS planner to create a plan - so you will need an A* algorithm implementation (or similar) to find a “path” where an available actions is a “step” in that path.
- There are plenty of resources online that will help you get started with a simple implementation. There is a Unity Learn project that deals with a similar topic.
- You can easily find a free copy of the original papers published by Jeff Orkins, e.g. here. It’s clearly written and very educational.
- There are free Asset Store implementations like this one that you can use as a learning resource as well.
I hope this helps you get started!