- Home /
How to pick up and drop an item in 3rd person
Hi,
I'll start by saying I'm still fairly basic at coding - I can read it fairly well but havent yet got my head fully around writing my own, if that makes sense. Usually my coding will be a mixture of following tutorials and then customising it to my particular needs.
Anyway, I have been searching for days for a way to implement a pick up and drop mechanic in a prototype 3rd person/top down game. Most tutorials/examples/answers are for 1st person, and so depend on the camera for the raycast - I thought it would be as simple as substituting the camera reference for an empty transform reference (attached to the player), but it doesnt seem to work (don't get any compile errors, it just does nothing). The few 3rd person ones I have found seem to be outdated (and in javascript), or use triggers instead of raycasts - I will have many items close together, so I'm assuming raycast is the best solution as using a trigger on each item will result in unwanted overlap.
So my prototype is twin stick controls using an xbox controller. Ideally I want the player to be able to pick up and drop an item with the same button - 'fire1'.
Any advice at all would be great. Thanks.
Simply show us your "first-person-code" and we could help you to modify this code. But if you want to do it at your own here is how I would do it: 1. Add a script at the camera object 2. Let this script do a raycast 3. If your raycast hits something check if this is is something to pick up if(hit.transform.tag == "pick") { }
4. store this object in a variable to drop it later 5. Do some action (pick up animation etc.) whit your stored object. 6. Give the pic up object a script which handles its properties
I hope this is a good starting point which helps you. [I'm not a native Englisch speaker so please forgive me my mistakes]
Your answer
![](https://koobas.hobune.stream/wayback/20220613034709im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
WorldToScreenPoint returning ridiculously high number 1 Answer
OnMouseButtonDown raycast 2 Answers
Phyics.Raycast alternatively returns True/False with static input 2 Answers