Download

Picking up objects

I were just wondering, how can I make it so the player can pick up objects (not add it to an inv.) and hold it in front of them and move it around, kinda like in skyrim? (and ofc being able to drop it anywhere)

There’s a few ways I guess, but one way is to add a socket or an Arrow to your Pawn in front of the camera/player. Use this for the transform.

Then create a base class for your “interactible items” (or use interfaces/component… not sure the “best” method, there are several) and have a gated tick that opens when it’s interacted with, that sets it’s transform to that of the socket/arrow you made earlier. So when you interact with it, it’ll move to in front of the players camera (the socket) on tick, when you drop it, close the gate. Make sure gravity is enabled and it should fall I think.

If you need more specific help just mention at which stage :slight_smile:

about the base class stuff, what do I do there? x) do I create a blueprint class? and if so, what type of class?

Yeah, just create a Blueprint Actor (and put a static mesh inside that). Then when you make different items, create them as a child of this Base Class.

The reason you do this is so that every child will inherit the base functionality to act as an “item”, this is just so you don’t need to put the same code in every single item.

Instead you have one base class that has all the functionality to be picked up, and put in front of the players camera.

ok I’m sorry but I’m really stupid when it comes to this xP but how do I make the gated tick thing and the rest? (how to get the obj. to know when it’s interacted with and set the position to the transform of the arrow)

I made a little example project to show you how it’s done. Every node is annotated to explain what’s going on. This should help quite a bit. I ended up doing it slightly differently than I said, it’s all done in the main pawn in the Blueprints folder.

Simply make a child class of the Base_Interatible_Item and it will be interactible. You can also do this with interfaces, but I figured I’d teach you the basics first rather than adding that extra step. If you’d like too simply research Interfaces once you’re done understanding how this works.

Hope this helps!