I’m currently working on a game that requires a very simple inventory.
The player can take off their hat, and store one item in it, and drop that item when they choose by shaking their hat. The item should fall with physics so that it can be used for puzzles!
The inventory needs to only be one slot big, and essentially needs to follow this logic:
//
If overlap with item and press (pick up button) play pick up animation and destroy item.
If press (drop button) and item is currently held, play shaking hat animation and create item.
//
It sounds pretty simple, but I’m still a beginner with code and am not sure how to translate this into code! Any pointers would be much appreciated! ^^
I followed a few YouTube tutorials, but ironically they were too complicated for the system that I need. They all included multiple slots and stackable items, but all I need is one slot and the ability to be able to pick up and drop the item!
Incase this helps, the game is pixel art 2D with the character and everything they interact with being in this style, but the world is 3D! I already have the hat animations!
You can make a blueprint which contains a mesh and a collision volume.
In the code of this BP, you make sure that it only accepts input when the player is overlapping the box.
When the player is overlapping, and presses ( interact ), you save in a variable ( in the player ) what the mesh is, and destroy the BP. Play the pickup animation.
( If the player tries to pick something else up, it’s not ok, because the mesh variable is set. )
When the player wants to drop the item, spawn a new BP, set the mesh, and enable physics. Clear the mesh variable. Play the drop animation.
Where your SpawnActor BP had ‘mesh’, mine has ‘owner’ and the mesh cannot plug into this part. I’m not sure why, but I’m hoping its just a rookie mistake or simple error on my part! ^^ I included all the code just in case its something that’s obvious, but that I can’t spot.
The only thing that may be a little different is the names of my objects. Any references to a Sugar Cube are about the pick up/ drop object - in case its a bit confusing!
So to make a sugar cube pickup, you just put the BP in the level and set the mesh to a sugar cube. Or, if you want, you can make the sugar cube a child actor of the main pickup BP ( by right clicking in the content browser ) and set the cube there…
Same thing when you spawn it, because you set that variable to ‘expose on spawn’ it appears in the spawn call, and you can set it from the character.
What is the difference between the variables ‘Sprite’ and ‘Carried Sprite’ ? I’m currently trying to follow the first image, but I’m a little confused about the section ‘Set Carried Sprite’, as I don’t seem to have it in my variables.
Is it a new variable I need to make, or a rename of another variable?