Continuing Feature Parity Part 10 (Patreon)
Content
Cooking recipes have been complete! First let's see it in action:
There were a lot of problems that had to be solved to make it work. To start, let me summarize how the cooking works:
If you access the cooking mod, you can call the function Cook( x ) and pass in an item attribute string. The mod will then process this attribute and figure out how to get that item. For example, if I pass in "pastry", the mod will figure out what steps it needs to follow to cook a pastry. How does it know what to do? Because when the mod starts up, it allows you to specify independent cooking actions. Example:
- mortar + wheat = mortar with wheat
- mortar with wheat + pestle = mortar with flour
By telling the mod how to do independent cooking actions for the character, the cooking mod will put these steps together in the correct recipe order to arrive to the target. This is equivalent to teaching the character how to cook and perform specific cooking actions! So all I had to do was tell the character that pastry is just 3 flour, the character will then automatically create a recipe based on the end goal of 3 flour. Visually it looks like this:
That means that if anybody wanted to expand on the cooking abilities of the character, all they have to do is add their cooking action to the mod and then create a recipe based on the available actions. Here is an example of me adding cake:
Internally this was implemented with a short A* pathfinding. Worked well. The entire purpose of this is so cooking can be modded in a stupid easy way. Just call Cook( x ) and be done with the action.
Another problem that I had to solve is how to let the characters be aware of nearby items (so they know that they can grab them to cook). Characters were only aware of items if they were visible. So if they turned around after completing a recipe step, they could have accidentally stopped looking at an ingredient that they needed and it would cause the character to fail the cooking. The solution was to never clear the array of visible items. This means that when a new item is seen, it gets added to the character's vision array. If it stops being seen, then just ignore it but still keep it in the vision array. This effectively works like memory. If a character sees an item, it will be from then onwards always be aware of the existence of that item even if it looks away.
Some other problems I had to solve involve physics. One problem I was stuck on was getting the characters to stop getting their hands stuck as they tried to reach for items. Shown below:
The problem was that the hand would keep pushing down onto the table because it could not see the table. To fix this I stuck in a small physics test that elevates the hand to prevent it from trying to clip into the table:
The cyan cross that appears in the gif above is the indicator that the hand should stay above that point so it doesn't clip into the table.
So now that the system is ready I'm gonna be adding more cooking props like the mixing bowl and mixing spoon so the character can make recipes based on mixing eggs with flour and batter. I also have to implement visually adding the flour on the mortar. At the moment adding the wheat or crushing the wheat with the pestle does not have any visual effects to show the flour/wheat seeds. It will need to be added in a way that allows modding to work.
Also I am still tweaking and smoothing out the animations. The fact that it's all entirely physics based can make for some wonky behaviors but I think it adds charm to the characters.
Also reminder I will be having a Twitch.tv/ custom mod workshop to get people started this weekend July 11th Sunday @ 11AM PST.
Tune in on Sunday or stay tuned!