Crafting system
This is most of the Crafting system I wrote for "Slime: a dungeon Escape" (Unreal).
My objective when writing this code was to create a crafting system of the appropriate complexity for our game that made it really easy for designers to create new crafting recipes that automatically work in the game.
In the game the player can only hold one item at a time(currentlyHeldItem), and when the player attempts to pick up a second object (newHeldItem) it will trigger the crafting system. The designers must create Data Assets called "Recipes" that hold two names and a prefab. When the Crafting is activated, it will compare the names of the currently held item and the new held item with the names on the recipes, if there is a match, then it returns true, destroys the 2 items and instantiates the crafting result item.
Character movement
This is some of the Character movement I made for "Slime: a dungeon Escape" (Unreal).
We wanted 2D platformer movement, with wall jumping, and several quality of life functions to make the platforming feel good.
I started by Creating a state machine for the player with 3 states: Grounded, Airborne and WallCling. I put 3 tiny colliders on the left, right and bottom of the character to detect collisions with wall and help determine what state the player should be in. I also included things like Coyote jump that has a grace period after leaving the ground that allows the player to jump as well the opposite, a grace period for when the player tries to jump too early before touching the ground.
I save the information of the prior state to help with special cases like the grace periods on wall jumps.
Calculating dice roll



This is the code I wrote for my current project "SlapKnight"(Unity).
When I wrote this code I did it with the intention of later on adding more types of dice, like dice with 4, 8, 12 or 20 faces.
The code takes into account the dice forward vector and it add a rotation offset to it to mark the different faces, to make a d12 dice one must input 12 to the "Dice sides" and input the proper offset visually for that kind of dice.
When dice is rolled by adding random force and rotation to in a certain range then when the dice rotation speed reaches near zero, it calculates the angle between each side vector and the up world angle, the side with the lowest angle is declared the number the dice landed on.