Picking up items

I’m making a backrooms game and a common request is that I make a script that allows the player to pick up items. I do not know how to do this, and I require assistance from a more experienced programmer than I am. Please help asap.

Hi @slatherycproductions,

There is a number of picking tutorials and examples in this page:

https://developer.playcanvas.com/en/tutorials/?tags=raycast

1 Like

Hey,
Thanks, that could be useful in the future, but I need something, preferably a script, that allows the player to pick up items. There does not need to be a inventory feature, I just need something that will allow an item to be “picked up,” meaning just held in front of the player, and traveling along with them.

Hi @slatherycproductions! Maybe my drag and drop example project can help you.

https://playcanvas.com/project/874243/overview/example--drag-and-drop

1 Like

Thank you so much!! That’s perfect. One thing though, is there a way to reduce the range?

Yes, you can limit the raycast distance (for this you need to change the current way of raycasting) or check the distance before picking up (probably the easiest to do).

https://developer.playcanvas.com/api/pc.Vec3.html#distance

Probably going to go with a distance checker, how would I do this?

An easy way to check when you are in proximity to pick up and item is to use colliders and triggers:

https://developer.playcanvas.com/en/tutorials/collision-and-triggers/

As soon as you picked it you can add it as a child to your player, to get it to follow you.

Okay, I implemented the picking script into the game, but it cannot read properties of screentoworld, so Im getting an error

Probably because you didn’t attach the script on the camera entity.

ah, yes, it works now. Still haven’t figured out range, could you send me the code that changes range?

I have updated my example project.