How to Pick Up + Hold Objects in Unity (FPS)

In this video I show how to pick up, rotate, and throw objects in Unity.
CODE (YES YOU HAVE PERMISSION TO USE IT):
github.com/JonDevTutorial/Pic...

Пікірлер: 80

  • @kiryrumirz1615
    @kiryrumirz1615 Жыл бұрын

    I loved it completely, and the memes sajkdsakljd so good, hope to see more of your tutorials soon!

  • @josemanuel5205
    @josemanuel5205 Жыл бұрын

    Loved the tutorial, keep up the good work

  • @SleepyMatt-zzz
    @SleepyMatt-zzz7 ай бұрын

    For anyone struggling to figure out how to reference another script, I used a video by Game Dev Beginner "How to get a variable from another script in Unity (the right way)" to figure it out. Thank you Jon for this helpful tutorial.

  • @itsjustangel4544

    @itsjustangel4544

    7 ай бұрын

    hey I'm a beginner can. I watched the vid but I'm still confused on how to properly reference a script with in another? Can you tell me what code you put?

  • @SleepyMatt-zzz

    @SleepyMatt-zzz

    7 ай бұрын

    @@itsjustangel4544 I will try my best to remember what I did to the best of my ability. This won't be something you will be able to simply copy & paste: 1. first, in your FPS/Player controller script, you want to make the variables that control the mouse sensitivity is public, e.g. public float lookSpeedX = 2.0f; public float lookSpeedY = 2.0f; 2. Second, make whatever function that moves your camera is also Public, e.g. public void HandleMouseLook() 3. From here on we will make our way back to our PickUPScript, and similar to what the end of this video demonstrates, you want to declare the FPS controller script at the bottom of the section of the PickUpScript where you have declared your other public/private floats and bool variables. This is just telling the system that another script is going to be referenced. Simply call the script you want to reference and assign it a name. e.g. FPSController mouseLookScript; "FPSController" is the script I am referencing, and mouseLookScript is the name I have given it to declare it. 4. Now go to Void Start(), use the named variable we are going to use to reference the FPS controller, e.g. void Start() { LayerNumber = LayerMask.NameToLayer("holdLayer"); mouseLookScript = player.GetComponent(); } The variable we gave a name to will now be able to call the FPSController script we are using for our intended purposes. The section of this line that uses the "" characters is annotating what script we are referencing when called. 5. Now go below into our Void RotateObject() function, and inside the IF statement that calls for our rotate object input, use the reference variable we created to call the variables we made public earlier that controls the mouse sensitivity, e.g. if (Input.GetKey(KeyCode.Mouse2)) { canDrop = false; //disable player being able to look around mouseLookScript.lookSpeedX = 0f; mouseLookScript.lookSpeedY = 0f; Here we are calling the variable we created to reference the fpsController script, and we are calling the variable from our fpsController that controls our camera sensitivity. the reason why we are setting both lines to 0 is because this is where we are freezing the camera when we press our desired input (I set mine to Mouse2/middle mouse button). 6. Now we go below to our else command where our "canDrop" command is and type the same lines we just used above, e.g. else { //re-enable player being able to look around mouseLookScript.lookSpeedX = 2.0f; mouseLookScript.lookSpeedY = 2.0f; canDrop = true; } Just make sure to type the default camera sensitivity value is the same as the fpsController script we are referencing, which will re-enable the camera to move. That is all I can remember off the top of my head, hope this helps. I'm sure there is a better way of doing this, but I'm still an amateur. The Fps controller I am using is based on code created by Comp-3 Interactive.

  • @-jxvi2951

    @-jxvi2951

    25 күн бұрын

    What code did you use?

  • @mdmushiransari2676
    @mdmushiransari2676 Жыл бұрын

    Thanks!!!! it is easy to implement and can be easily extended

  • @hemanarthanamaly4810
    @hemanarthanamaly4810 Жыл бұрын

    NO WAY YOU ARE NEW , i want you to be the new brackeys because editing , commentary and tutorials like this are GOLDEN.

  • @arinwald
    @arinwald Жыл бұрын

    Man, you are a King

  • @JWoods456
    @JWoods4565 ай бұрын

    Absolute Legend, Thank you

  • @davidgil1171
    @davidgil1171 Жыл бұрын

    Man this is so gooood! Can u do a tutorial on an Inventory System?

  • @ilikepieandgames
    @ilikepieandgames2 жыл бұрын

    Sorry but how does this video only have 60 views when its the best method of doing this I've found

  • @jondevtutorials4787

    @jondevtutorials4787

    2 жыл бұрын

    Thanks!

  • @metaDeWeta
    @metaDeWeta5 ай бұрын

    Very good, thank you so much!!

  • @dssolve
    @dssolve5 ай бұрын

    Make sure that the "Static" checkbox is not ticked in the Inspector at the top right corner. Some objects have this ticked by default

  • @skylarl.4571
    @skylarl.45712 ай бұрын

    hi! thank you so much for the tutorial! i'm a bit confused on how to lock the background lookaround rotation while you're rotating the item. could you advise on this? thanks!

  • @saltyorangejuice1010
    @saltyorangejuice1010 Жыл бұрын

    Best tutorial

  • @thewall694
    @thewall6946 ай бұрын

    amazing, dude

  • @vuxenn
    @vuxenn3 ай бұрын

    I loved your tutorial and script it's so useful and great. But i've a question: I want my pickable objects to be affected by my post process which is in my main camera object. How can i do that?

  • @Bombastic1726
    @Bombastic1726 Жыл бұрын

    Thank you so much

  • @Dev_Roids
    @Dev_Roids6 ай бұрын

    Thanks so much!

  • @bennysensei4662
    @bennysensei46623 ай бұрын

    Im a newbie of that. What is ur template you using? 3D, VR core, or something? Thanks

  • @aminnekarlsson
    @aminnekarlsson Жыл бұрын

    Great tutorial! I've implemented the script and managed to get it working. But when I pick up and throw the object, the scaling of the object change. How can i fix this. And my camera also rotates when rotating the object, is there any way to fix that?

  • @yesimhairy
    @yesimhairy Жыл бұрын

    Hello, great tutorial. I will definitely use it in the future! One concern I do have is if your rendering the object above everything, doesn't that mean that you can see it through walls? Sorry if the answers obvious but I haven't used this system yet. Thanks

  • @jondevtutorials4787

    @jondevtutorials4787

    Жыл бұрын

    Hey thanks for the nice comment. The layer gets rendered above everything, and since we only assign the object to that layer when we are holding it, the object doesn't appear through walls when it is on the ground.

  • @yesimhairy

    @yesimhairy

    Жыл бұрын

    @@jondevtutorials4787 Thanks for letting me know :)

  • @TooOldForML
    @TooOldForML Жыл бұрын

    Thank you! This worked great and was easy to implement. Edit: Got it working how I wanted :)

  • @kingdom216
    @kingdom216 Жыл бұрын

    how does the script change when using third person and player input system?

  • @huguesdepayens9558
    @huguesdepayens9558 Жыл бұрын

    This is nice because the object doesn't move when it hits walls

  • @backroomsarchives4628
    @backroomsarchives4628 Жыл бұрын

    hello, i have some problem, the script works until i take the object in my hand, as soon as i press E and the game pauses

  • @Harharharisstibky
    @Harharharisstibky Жыл бұрын

    hey man i want to ask is it ok if i put your yt user in the credits for the game im working on? thanks

  • @jondevtutorials4787

    @jondevtutorials4787

    Жыл бұрын

    yeah no problem :) Appreciate it

  • @mug4621
    @mug462110 ай бұрын

    hello how can ı use this when using urp ? do i just turn the broject into urp _?

  • @bigdong7505
    @bigdong7505Ай бұрын

    idk why but all of the things i tested keeps resizing when i'm holding them and move my camera

  • @duraeman2893
    @duraeman28937 ай бұрын

    i can see the object through walls, how can i fix this?

  • @sushilord4865
    @sushilord4865 Жыл бұрын

    Unsure if you're still responding to comments or not but I have a slight problem. Picking up items is fine at first but for some reason after a bit it is a pain to pick up items. There's like a 90% chance the object cant be picked up and it gets very annoying. Any fixes? I'm using mesh colliders if that helps!

  • @BjornBrnk

    @BjornBrnk

    2 ай бұрын

    Remove the mesh collider

  • @bubble12
    @bubble12 Жыл бұрын

    i got this error, pls help. (A game object can only be in one layer. The layer needs to be in the range [0...31])

  • @kage8969
    @kage8969 Жыл бұрын

    So, I didn't necessarily have an issue with adding the code to my player but when I go up to an object that has the "canPickUp" tag it does nothing.

  • @Kiwi_Inventor

    @Kiwi_Inventor

    4 ай бұрын

    same

  • @affenkratzer
    @affenkratzerАй бұрын

    does someone know why my cube streches after picking it up?

  • @Blend.mpeg4
    @Blend.mpeg411 ай бұрын

    Лучший

  • @krunchyfps
    @krunchyfps11 күн бұрын

    Please help. It says the name "Pickable" does not exist in the current context. The name of my Layer is Pickable.

  • @lennienicolelorenzo4212
    @lennienicolelorenzo42127 күн бұрын

    hI, can someone help me pls every time I try to click the "E" to pick up the object it doesn't do anything.

  • @elcolgaodeturno485
    @elcolgaodeturno485 Жыл бұрын

    Hi, i knwo this video is old but i'm trying to use your code. I have a weird problem. When i pick up an object his scale changes. Making more big or more little. Any idea whats happening?

  • @nikolaandric8041

    @nikolaandric8041

    2 ай бұрын

    same problem, did you fix it

  • @someguy9163
    @someguy91639 күн бұрын

    also what is ECM it have an error

  • @_Leaf53
    @_Leaf534 ай бұрын

    If anyone knows, why does the object teleport underneath my player when i drop it?

  • @jankystreams3337
    @jankystreams3337 Жыл бұрын

    Hey, awesome video. I have a problem when picking up the item. I have a post process volume on my main camera, but when I pick up the item the effect doesn't apply onto the item until I drop it. I tried putting a volume on the other camera also, but it doesn't work still. Solutions?? Edit: Also, it clips through the map frequently.

  • @jondevtutorials4787

    @jondevtutorials4787

    Жыл бұрын

    Post process effects act on layers, you should have the option to select/add layers in the inspector for the post processing effect. As for the fact that it clips through the map, I think there is a StopClipping() func. that you may want to look at which tries to stop the the object from being placed through colliders. It's at the very bottom of the code, try editing the last few lines to your spec.

  • @jankystreams3337

    @jankystreams3337

    Жыл бұрын

    @@jondevtutorials4787 Thanks!

  • @hollowsnest518
    @hollowsnest5187 ай бұрын

    I keep getting a layer error saying A game object can only be in one layer. The layer needs to be in the range [0...31] someone please help me rah

  • @summerwheels
    @summerwheels21 күн бұрын

    why cant i pick up anythinggggg, i try to follow these tutoirals but nothing works

  • @someguy9163
    @someguy91639 күн бұрын

    pls help me i use the urp not the normal one pls help :(

  • @MedicMainDave
    @MedicMainDave Жыл бұрын

    I'd have one suggestion. Use Interfaces instead of Tag, it's just better overall :P

  • @KikiKilo
    @KikiKilo2 ай бұрын

    When I click play, the object I want to pick up is just gone

  • @Tako874

    @Tako874

    Ай бұрын

    Have you moved around, picking up an object with this code near a wall makes it clip into the wall, if you still don’t see it, it might be the layers

  • @othmanmoat
    @othmanmoat6 ай бұрын

    Hey has anyone figured this out in URP?

  • @pietrosprudente
    @pietrosprudente5 ай бұрын

    This is for anyone who wants to rotate the object to world space! Replace this: heldObj.transform.Rotate(Vector3.down, XaxisRotation); heldObj.transform.Rotate(Vector3.right, YaxisRotation); With this: heldObj.transform.Rotate(Vector3.down, XaxisRotation, Space.World); heldObj.transform.Rotate(Vector3.right, YaxisRotation, Space.World); Hope this helps! 🧀🧀

  • @pebbleshmebble8142
    @pebbleshmebble8142 Жыл бұрын

    my cube disappears when I press E. Can you please help

  • @ilhamnarendra770

    @ilhamnarendra770

    10 ай бұрын

    same broooo, how is it now??

  • @HiHoSHOW
    @HiHoSHOW Жыл бұрын

    I don't have clear Flags and depth option in my camera inspector!

  • @jondevtutorials4787

    @jondevtutorials4787

    Жыл бұрын

    Are you using URP perhaps? If not that can you tell me what version of unity you are running?

  • @HiHoSHOW

    @HiHoSHOW

    Жыл бұрын

    @@jondevtutorials4787 yes I was using it and I turned it off and now I have them. But there is another issue with the code. When I pick up a cube for example and look around the cube changes its scale. Why is this happening?

  • @HiHoSHOW

    @HiHoSHOW

    Жыл бұрын

    @@jondevtutorials4787 I'm facing a weird issue sometimes when I throw an object, it doesn't always gets thrown forward. sometimes towards the player itself.

  • @jondevtutorials4787

    @jondevtutorials4787

    Жыл бұрын

    @@HiHoSHOW perhaps the player is blocking, try changing the point where it is being thrown from. Else check how direction is being calculated in the addforce method, perhaps you are using worldspace not local space.

  • @ilhamnarendra770

    @ilhamnarendra770

    10 ай бұрын

    @@jondevtutorials4787 i use urp, 2022.3. and i didnt have those two. and now my object is invisible when i picked it up.., any solution??

  • @huguesdepayens9558
    @huguesdepayens9558 Жыл бұрын

    How come when I throw it at the floor, it goes through the floor?

  • @yesmylightingsucks

    @yesmylightingsucks

    Жыл бұрын

    box collider

  • @RealEngineerGaming
    @RealEngineerGaming23 күн бұрын

    This tutorial isnt working for me. It might be because I dont know how to reference my FPS script, but none of this actually works for me, man. Its always these seemingly easy tutorials that are the most complex. Or maybe im just stupid

  • @GGC4D
    @GGC4D Жыл бұрын

    Can you make a version of this to be mobile friendly? Like for example. Edit this script so then it can work for say making a mobile game

  • @williammason1938
    @williammason19385 ай бұрын

    it dont work for me :/

  • @JimmyFireZOnYT
    @JimmyFireZOnYT7 ай бұрын

    The throw doesn’t work and now the cube is on my camera, forever

  • @new_source

    @new_source

    2 ай бұрын

    same :C

  • @ilhamnarendra770
    @ilhamnarendra77010 ай бұрын

    can someone help me.., it doesnt work?? edit : i use urp and some things change with the camera. but i dont know why i cant pick up the object. i already assigned the tags and all the stuff, checked several times and i dont seem to find the problem why. 2nd edit = i figured it out, turns out it needed rigidbody. but now the object is invisible when its picked up. any solution??

  • @Handvr

    @Handvr

    6 ай бұрын

    me too!

  • @lazikbro12
    @lazikbro12 Жыл бұрын

    it doesnt work when i click e

  • @ilhamnarendra770

    @ilhamnarendra770

    10 ай бұрын

    assign rigidbody and box collider

  • @lennienicolelorenzo4212

    @lennienicolelorenzo4212

    7 күн бұрын

    @@ilhamnarendra770 it's still not working

  • @hemanarthanamaly4810
    @hemanarthanamaly4810 Жыл бұрын

    you have discord man? i dont wanna forget you