How to Pick up and Drop Objects/Items! (First and Third Person, Unity Tutorial)

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 พ.ย. 2024

ความคิดเห็น • 278

  • @CodeMonkeyUnity
    @CodeMonkeyUnity  2 ปีที่แล้ว +3

    🎮Get the Synty Shops pack cmonkey.co/synty_shops_pickupdrop
    ✅Get the Project files and Utilities at unitycodemonkey.com/video.php?v=2IhzPTS4av4
    🌍Get my Complete Courses! ✅ unitycodemonkey.com/courses
    🔴 RELATED VIDEOS 🔴
    Kickstart your game with First and Third Person Controllers! (FREE Unity Starter Assets) th-cam.com/video/jXz5b_9z0Bc/w-d-xo.html
    SMOOTH with LERP! (Move, Rotate, Float) th-cam.com/users/shortsjAN2IoWdPzM
    What are Interfaces? (C# Basics) th-cam.com/video/MZOrGXk4XFI/w-d-xo.html

  • @michaelwilson8461
    @michaelwilson8461 2 ปีที่แล้ว +6

    So ...
    does anyone else just watch random videos from Code Monkey?
    I'm just taking a break from working on a project (brain is melting). It's kind of like shopping, you would be surprised at all the things you didn't know you needed until you saw it sitting there on a shelf lol. Thankfully unlike most of my random shopping trips, I don't leave here feeling broke and guilty lol.
    Thanks for everything you do man, its muchly appreciated.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      I watch tons of random game dev and non-game dev videos so yup! I'm glad you like the videos! Thanks!

    • @WesmanU2012
      @WesmanU2012 8 หลายเดือนก่อน

      thats cool@@CodeMonkeyUnity

  • @alienouz
    @alienouz 2 ปีที่แล้ว +5

    nice video as usual,
    I like how you always make use of the starter assets

  • @alec_almartson
    @alec_almartson 2 ปีที่แล้ว +11

    This is Super cool. 💯👍🏻
    Making your 3D Character able to grab objects (items, swords, etc) is an important part of the fun, in GameDev.
    Thank you for sharing your knowledge with us.

  • @Liam_The_Great
    @Liam_The_Great 2 ปีที่แล้ว +2

    Your tutorials are always so helpful, thanks a lot

  • @788garagestudio
    @788garagestudio 2 ปีที่แล้ว +1

    Thanks Code Monkey, this helped me with my pick up feature I was implementing in my game!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      That's great to hear, best of luck with your game!

  • @geengee5085
    @geengee5085 2 ปีที่แล้ว

    Ive been looking for this everywhere...
    I love you code monkey 💪😖💙💙💙

  • @MarkVinkNL
    @MarkVinkNL 2 ปีที่แล้ว +1

    Thanks for the cool tutorial! I noticed you did some if/else nesting. Might I suggest you have a look at quick returning/return early pattern. It was a real eye opener for me, and made my code much clearer to read, for me and my colleagues. Keep up the good work!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      Yup that is an interesting pattern that sometimes I use. If I were to use this in a final game I would probably refactor to use the new Input system and get an event for the input instead of an if which would help reduce the ident level and leave just one if-else

    • @MarkVinkNL
      @MarkVinkNL 2 ปีที่แล้ว +5

      @@CodeMonkeyUnity I don't think you need to refactor that much, just switch some stuff around. If I may be so bold, think of it like this:
      If keycode != E then Return (1 nesting lvl gone).
      If objectGrabbale != null, drop and return. (That eliminates the if/else. After that you can continue with your pickup logic as you do now)
      If raycast doesn't find an object, return
      If object isn't grabbable return
      Grab object
      This way you code becomes more a set of checks to see if the function may be executed further, instead of the function get entirely executed, but only do things if...

  • @SwayamVaza-qr8vs
    @SwayamVaza-qr8vs 5 หลายเดือนก่อน

    Thank you sir, this tutorial helped me alot 😃

  • @B4NTO
    @B4NTO ปีที่แล้ว

    Awesome tutorial as always and useful for my current uni project :)

  • @coreyholt8522
    @coreyholt8522 4 หลายเดือนก่อน

    Super useful video as usual

  • @supertenchoo4271
    @supertenchoo4271 2 ปีที่แล้ว

    great video and very good explanation, thanks

  • @disobedientdolphin
    @disobedientdolphin ปีที่แล้ว

    Very nice video, thank you!

  • @GrantCarvalho
    @GrantCarvalho 2 ปีที่แล้ว

    Excellent video thanks!

  • @Updates_
    @Updates_ 2 ปีที่แล้ว +1

    Wow that's awesome tutorial.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      Thanks!

    • @Updates_
      @Updates_ 2 ปีที่แล้ว

      @@CodeMonkeyUnity your welcome ☺️

  • @fess24
    @fess24 2 ปีที่แล้ว

    Wow! Thank You!

  • @jud.su.5developer895
    @jud.su.5developer895 2 ปีที่แล้ว +1

    Very nice 😊

  • @itsdonix
    @itsdonix ปีที่แล้ว

    Great Tutorial! I Have A Question, Is There Anyway i can make an interaction text?

  • @vipex5566
    @vipex5566 2 ปีที่แล้ว +3

    the next tutorial can be the ones with the area where you can sell items when you put them in that area?

    • @imiplacsarmalele2374
      @imiplacsarmalele2374 2 ปีที่แล้ว

      yes, I really need this tutorial too ... please code monkey make this tutorial 🥺

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +5

      Yup the next tutorial does cover how to identify if an object is placed in a certain position and what to do with it.

  • @alexanderoneill3018
    @alexanderoneill3018 ปีที่แล้ว

    GAH! I was hunting for a null exception error for over an hour; turns out I had an extra set of curly braces after the line
    "if(Physics.Raycast(playerCameraTransform.position...", had to scroll over to see them!
    If you're getting a null exception error, watch out for those braces!
    Great tutorial, thanks for your work!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Heh yup always be very careful with how the code is typed, one small change can cause all kinds of issues!

  • @omarjavieraguirresegura3276
    @omarjavieraguirresegura3276 2 ปีที่แล้ว

    Great video!! Hope you can show us how to add strafe animations to Third person shorter , that you create previously

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      The third person shooter already uses multiple layers in the animator to animate the upper body and legs differently, so the only thing it needs is extra animations for strafe left-right, etc

  • @MarushiaDark316
    @MarushiaDark316 2 ปีที่แล้ว +16

    I notice in a lot of your tutorials, you'll make local variables (like in this case the pickup distance and lerp speed) to have the flexibility of changing the values; but why not just make them serialized fields since you have other serialized fields already?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +12

      It's more for code readability rather than easy editing. unitycodemonkey.com/video.php?v=CQ5xHgRZGQo
      But yup if I wanted them easily editable I would indeed make them SerializeField

    • @jtlewis81
      @jtlewis81 2 ปีที่แล้ว +1

      @@CodeMonkeyUnity Yeah, I noticed that too, and I always add a [SerializedField] so I can easily customize in the inspector.

    • @AndreiGontcharov
      @AndreiGontcharov 2 ปีที่แล้ว +1

      IIRC local variables in a method mean that every time the method is called - that variable is created from scratch every time. Good for rapid prototyping but for a final product this can have a performance hit if you have a bunch of methods and code that have a bunch of local variables that are constantly being recreated for a method call. If the method was a method that would reasonable only run once or twice during a game's lifetime then that would be fine.

    • @r1pfake521
      @r1pfake521 2 ปีที่แล้ว +4

      @@AndreiGontcharov I wouldn't use the word "recreated", but yes, in theory there is a "overhead" when using a local variable vs fields, but in reallity you will not notice a performance issue (or even a relvant difference) with local variables, not even if you have 50 local variables per method. So who ever told you that, please don't listen to any of their advice and always remember "premature optimization root of all evil"

  • @DarthPackman
    @DarthPackman ปีที่แล้ว

    Lovely tutorial, any idea how to make it so players can aim down and jump onto the objects to fly?

  • @lemetamax
    @lemetamax 2 ปีที่แล้ว +1

    Nice tutorial as always. But I hoped that the third person system would use procedural animation instead of being telekinetic. That oughta be cooler.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +3

      I covered that part here unitycodemonkey.com/video.php?v=UL2EbxqwozM
      Pretty simple to add to this system

  • @YoMateo.
    @YoMateo. 2 ปีที่แล้ว +37

    Whoever's reading this, i pray that whatever you're going through gets better and whatever you're struggling with or worrying about is going to be fine and that everyone has a fantastic day! Amen

    • @dunderguy
      @dunderguy 2 ปีที่แล้ว

      SHUT UP

    • @pitnie8392
      @pitnie8392 ปีที่แล้ว

      Thx!

    • @Noobis9
      @Noobis9 ปีที่แล้ว

      Says Quandale dingle

    • @LePajup
      @LePajup ปีที่แล้ว

      All the best to you !

  • @joey546
    @joey546 2 ปีที่แล้ว +7

    Not a fan of blueberry muffins, I see.

  • @Ignaciodev
    @Ignaciodev ปีที่แล้ว +1

    hello just wanted to tell you that the layer mask didnt show the player, so i would hit the player instead of the obect, so i removed the layer mask part from the code and it works fine

    • @Ignaciodev
      @Ignaciodev 11 หลายเดือนก่อน +1

      Me of the future, I just had to make the player mask, since it didnt come by default in my project

  • @joshsheppard6892
    @joshsheppard6892 ปีที่แล้ว

    Tutorial uses old input system, putting code in a use defined function instead of update allows it to be called and used with new input system performed action.

  • @NightsoftInteractive
    @NightsoftInteractive 2 ปีที่แล้ว

    Finally we can put a bucket on peoples head via scripting and steal their sweet rolls 😆
    Grabbing objects is an important and often overlooked mechanic in any immersive sim, survival game and sandbox rpg.
    Will definitely come in handy for my indie RPG, thanks a lot 👍

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Heh yup if you used raycasts for enemy detection from the NPCs head you could definitely do that!

    • @NightsoftInteractive
      @NightsoftInteractive 2 ปีที่แล้ว

      @@CodeMonkeyUnity That's the plan 😉

  • @الزعيمهيسوكا-ه7ش
    @الزعيمهيسوكا-ه7ش 2 ปีที่แล้ว

    Thanks so mush ❤️❤️❤️

  • @svetliobg_pro3647
    @svetliobg_pro3647 2 ปีที่แล้ว

    I have a question, if theres something in the bucket and you pick up the bucket will the item inside pickup too? Also great tutorial :)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Yup! The bucket is moved using physics so any objects in there will indeed move along with it

  • @thg1nrediar
    @thg1nrediar 2 ปีที่แล้ว

    Thanks

  • @ТрофимНаталуха
    @ТрофимНаталуха 4 หลายเดือนก่อน

    if you turn off gravity, you can lift an object of any weight, or push it, and you can also fly on it. Is there a more professional approach to implementation?

    • @ТрофимНаталуха
      @ТрофимНаталуха 4 หลายเดือนก่อน

      I'm thinking of a way that would involve physics, like using the player's force variable to determine if the object can be picked up, or if the force is enough to just drag it slowly, or if it's impossible to affect the object at all, I've even tried I can write a speed calculation for an object based on its mass, but I can’t seem to implement it, can you tell me where to find ready-made code or a lesson?

  • @r6scrubs126
    @r6scrubs126 2 ปีที่แล้ว

    Great tutorial as always. But I have one question - is there any reason for putting the grabbing/movement code on the item that's being grabbed, rather than on the player? To me it makes more sense for it to be the player controller that handles moving the object towards the player, instead of the object needing to know about the player's camera location and move itself towards that

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      That's a bit of a design question, depends on exactly how you use it in your game, how your items differ.
      In my mind I was imagining expanding this system with more custom logic on a per item basis, so instead of just one script I would make it an interface and different items could handle the grab logic differently. Perhaps some items/objects don't have physics, perhaps some need to be setup/reset when grabbed/drop, perhaps some do something with their rotation, etc.
      But if all your items are meant to be grabbed in just one way then perhaps making the logic on the player script might make sense.

    • @r6scrubs126
      @r6scrubs126 2 ปีที่แล้ว

      @@CodeMonkeyUnity thanks for the detailed response, much appreciated. Yeah I did consider that as well but I couldn't think of any scenarios where different items would need to do something different when picked up, but yeah if there are some then that definitely makes sense to do it your way

  • @jdiezastronomy
    @jdiezastronomy ปีที่แล้ว

    Hi! Great tutorial. I missed something as it doesn't work with my scene. I'm not good at coding! By the way, why don't you post the First person with pick & drop to the Asset store
    ? So I can buy it and save hours.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      The first step is identify exactly what doesn't work, just saying "doesn't work" doesn't mean much. You can't locate the object in front of the player? You can't pick it up? The object doesn't move?

    • @jdiezastronomy
      @jdiezastronomy ปีที่แล้ว

      @@CodeMonkeyUnity I'm staring again from 0! One question; I'm on a Mac M2 MAX and the script was made using the Sublime text from the Mac. Is it ok or do I need another app for the script? Thanks!

  • @honokiii
    @honokiii 2 ปีที่แล้ว

    Hi! Thank you for a very good video as always.
    I just have a quick question about the input system of your choice. Why did you use the Legacy and not the new one? I'm not making fun of it or anything, I'm just curious how do you pick which input system you use.
    Personally, I'm more used on the legacy input but because of the tutorials that I am watching now, I have started to learn how to use the new Input System. But I'm still not there where I can use the new one easily, but I'm still using it as most of the videos I have watched is using it. Then after watching this, I just thought, should I still try and learn the new Input system? Or it's alright to work with the legacy input where I can work faster and comfortably?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +2

      Simply because of simplicity, it's extremely easy to use, no need to create an asset or anything, just one line of code and it works.
      However for a proper project I would indeed use the new Input System.
      In fact that's what I did in my latest long term project which was my TBS Course, in there while developing the game I kept it simple with the legacy input manager, however in the end of the game, during the polish stage, I went back and refactored it to use the new input system.
      So definitely use it before you release your game, but during the development phase use whatever you prefer, I covered it in this video if you want to learn how it works unitycodemonkey.com/video.php?v=Yjee_e4fICc

    • @honokiii
      @honokiii 2 ปีที่แล้ว

      @@CodeMonkeyUnity I see, thank you again!

    • @Hietakissa
      @Hietakissa 2 ปีที่แล้ว

      @@CodeMonkeyUnity is there any reason to even switch to the new input system if you don't want to make rebindable controls, I've heard it's more performant, but I don't imagine it's noticeable or significant. So in that case would it just be better to spend the time polishing and adding other features?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      If your game uses more than just a mouse, definitely refactor your code to use the new Input System at some point, it is so much better in many many ways. Easier to organize all of your inputs, all of your actions, easier to make it work with gamepad/touch/any input, etc.

  • @savionthomas4325
    @savionthomas4325 2 ปีที่แล้ว

    Lets say when you pick up an object, you want to control the direction its rotated towards. A flash light for example. I want to control where an object is facing/pointing. What would you recommend is a good starting point?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      For a flashlight you want to point it in the direction you're looking, so for that you would just set the objects transform.forward to be the same as the camera

    • @canertwo
      @canertwo ปีที่แล้ว +1

      Hey, for anyone coming here to look for this: I did what Code Monkey said with this code in the if (objectGrabPointTransform != null) block:
      transform.rotation = Quaternion.Euler(0f, objectGrabPointTransform.eulerAngles.y, 0f);

    • @TheAdventuresofShujaaandRafiki
      @TheAdventuresofShujaaandRafiki ปีที่แล้ว +2

      @@canertwo Thank you....Been trying to figure this out all day...Still trying to tweak it to my liking but it works when trying to throw the object instead of dropping it.

  • @NBAComparasions81
    @NBAComparasions81 8 หลายเดือนก่อน

    Nice tutorial, just what i wanted, but i can't figure out what is written the 14th line of PlayerPickUpDrop script?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  8 หลายเดือนก่อน

      What timestamp?
      if (Input.GetKeyDown(KeyCode.E)) ?
      That returns true when the E key is pressed

  • @ICECREAMALOT
    @ICECREAMALOT 6 หลายเดือนก่อน

    Hey CodeMonkey :) Thanks for the awesome tutorial! I implemented this system in my game, but there's one issue: my game is multiplayer, using networking code for game objects. I was wondering how you would implement a system like this to work in multiplayer. I got it to kind of work, but the delay on the client side is much bigger than on the server/host side. Then, I tried to attach the object to an attachment point, but I couldn't do that because the attachment point game object wasn't a networked game object. I really need a physics-based pick-up and drop system like the one found in games such as "One Armed Cook," for example.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  6 หลายเดือนก่อน

      In multiplayer you need to avoid changing the parent. Instead just make a script that on every Update tries to move the picked up object towards the hold point position, without changing the parent.
      If you just do that it should work fine, although might require some lag compensation to look good on the client since the physics will only run on the server

  • @mutlugameofhalit
    @mutlugameofhalit 7 หลายเดือนก่อน +1

    When player look at bottom cube is adding force to player capsule, how to solve this?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  7 หลายเดือนก่อน

      The easiest way is to disable physics on the object if too close. Or modify the physics matrix to make it only not impact the player.

  • @MarthKoopa
    @MarthKoopa ปีที่แล้ว +1

    Is it possible to add the held object's collision to the player? Say you were carrying a massive box, it would end up clipping through walls and glitching out. What's the best way to prevent that?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Depends on the character controller you're using and how you're testing for collisions
      You might need to do a BoxCast from the held object position towards where the player is moving to see if the player should move

  • @ManuGambino93
    @ManuGambino93 6 หลายเดือนก่อน

    @codemonkeyunity at the end when you grab de sandwich and move, the movement is still to jittery, is there a way to smooth that so I doesnt look like de sandwich is doing like small jumps forward ?

  • @PatrickK-er6yu
    @PatrickK-er6yu 9 หลายเดือนก่อน +2

    UMM YOU CAN PROP FLY

  • @chrisskyr623
    @chrisskyr623 2 ปีที่แล้ว

    I did everything you did but the objects are still jittery. But the tutorial is awesome!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      The more complex method is to modify the rigidbody.velocity yourself, that way you just tell the object to move in a certain direction instead of towards a certain position

  • @TUPGD
    @TUPGD 10 หลายเดือนก่อน

    Why not use Spherecast to pickup?

  • @MummyfiedRose
    @MummyfiedRose 9 หลายเดือนก่อน

    Trying to implement the idea of picking up a container (e.g. the cart) that has other grabbables inside, but since "Non-convex MeshCollider with non-kinematic Rigidbody is no longer supported since Unity 5." the container has to have a convex collider and ends up behaving like a box. :( Making the container kinematic makes it fly through things (terrain included) so not an option..

  • @jankystreams3337
    @jankystreams3337 ปีที่แล้ว +1

    No matter what I do my item is still extremely jittery. Can you suggest any other solutions to try please?

  • @nixonrulez
    @nixonrulez 5 หลายเดือนก่อน

    Unfortunately there is nothing about the fps hand interacting with objects. It is partly IK and the fingers are animated I guess, but I couldn't find a single tutorial or explanation. How do you pull a lever with a fps hand?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 หลายเดือนก่อน +1

      Yup use IK, I covered something like it here unitycodemonkey.com/video.php?v=UL2EbxqwozM

  • @Dwuckyy
    @Dwuckyy ปีที่แล้ว +1

    Hello! Great tutorial! I have a slight problem that i cannot fix for the life of me. I followed the tutorial everything works great but it showed an error where it said that unity basically requires the kinematic option to be on on the pickable objects so now everything i pick up goes through the walls and floors when i pick them up. When i drop them they fall perfectly on the ground but if i point it towards the floor and drop it it goes through. Cna you help? Thanks in advance!

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      It depends on how you move the object, it only has to be kinematic if you move the transform directly
      At 10:35 I don't have it as kinematic
      If you make it kinematic then yes it will go through objects, that's what kinematic does

  • @lietotajs4086
    @lietotajs4086 2 ปีที่แล้ว +1

    What would be the solution so that the item couldn't be dropped bellow ground(terrain)?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      When the item is "floating" it is still using physics, so if the terrain has a collider you won't be able to drop it on the other side

  • @B4NTO
    @B4NTO ปีที่แล้ว

    With this method it seems in our project that if pushed enough towards a wall it would eventually go through the wall? maybe its related to our other components on the player but not sure?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว +1

      Depends on how thing the wall is and how much force you apply, but yes if you keep forcing it eventually it will go through. If you don't want that to happen then the best solution is to only give the object a velocity instead of setting the position directly.

    • @B4NTO
      @B4NTO ปีที่แล้ว

      @@CodeMonkeyUnity Thank you :) for you help as always. This might be a bit of a trickier question. But in our game we can carry these objects but if they get below us they can sometimes push player up while carrying it. should i perhaps disable physics collision between player and this object when i carry it or do you have any better suggestions?
      - edit -
      decided to lower the mass of the grabbable object to 0.1 and player has 1.0 which seems to work kinda good

  • @OfflineOffie
    @OfflineOffie 2 ปีที่แล้ว +2

    Could you please consider switching to dark themes in Visual Studio and Unity?
    Switching between the game and blindingly full bright IDE makes it hard for me to watch as it hurts my eyes.
    You probably do prefer the white theme, but around 80% of people use dark themes so I believe most of the people would also agree!
    Thanks!

    • @rob3rtsayshi
      @rob3rtsayshi 2 ปีที่แล้ว

      I wonder where you get your stats haha

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +6

      Sorry but dark mode burn my eyes, I literally cannot do it

    • @kloa4219
      @kloa4219 2 ปีที่แล้ว +1

      @@CodeMonkeyUnity based

    • @martin-schoen
      @martin-schoen 2 ปีที่แล้ว

      Looks like it's time for a mode between dark and light... The ugly purple theme ^^

  • @johndouglas6519
    @johndouglas6519 2 ปีที่แล้ว +1

    What if you wanted to place them(with rotate) instead of just dropping?

    • @johndouglas6519
      @johndouglas6519 2 ปีที่แล้ว

      @@eroll022 i see would give it a try, thanks for the tip.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +2

      I covered one method of 3D rotation in the item inspect video unitycodemonkey.com/video.php?v=tJ_ycboPFmY
      You could attempt that method or something based on key inputs to rotate various axis
      Or do what that game Hydroneer does which is fix the object in place, so if you want to "rotate" it you just grab it from a different angle.

  • @lunark202
    @lunark202 7 หลายเดือนก่อน

    Why is my object flickering even though I'm doing exactly the same thing? After I hold the object in my hand, I turn off the Use Gravity feature.

  • @LumenDev-u1z
    @LumenDev-u1z 11 หลายเดือนก่อน

    Ik this video is almost 2 years old now but is it possible to keep the velocity of the object when i let go of it allowing me to be able to throw the object by rotating my player and letting go at the right time?

    • @insop6432
      @insop6432 10 หลายเดือนก่อน

      you can use this:
      void FixedUpdate()
      {
      if(pickPos != null)
      {
      Vector3 targetDestination = pickPos.position - rb.position;
      rb.velocity = new Vector3(targetDestination.x, targetDestination.y, targetDestination.z) * speed; //This way the object moves at a velocity instead of changing position
      constantly.
      rb.useGravity = false;
      }
      }
      public void Grab(Transform pickPos)
      {
      this.pickPos = pickPos;
      }
      public void Drop()
      {
      pickPos = null;
      rb.useGravity = true;
      rb.velocity = rb.velocity/5; //you'll also want to divide the velocity by a number to prevent the player from throwing it too far.
      }

  • @Survivor_Shelter
    @Survivor_Shelter 8 หลายเดือนก่อน

    Can you tell me how to make the same sight as yours in the form of a dot?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  8 หลายเดือนก่อน

      It's just a circle image in the middle of the Canvas

    • @Survivor_Shelter
      @Survivor_Shelter 8 หลายเดือนก่อน

      thanks@@CodeMonkeyUnity

  • @o1497
    @o1497 ปีที่แล้ว +6

    For anyone who still thinks its to jittery, change the fixed update to this: private void FixedUpdate()
    {
    if (objectGrabPointTransform != null)
    {
    float lerpSpeed = 10f;
    Vector3 targetPosition = objectGrabPointTransform.position;
    // Smoothly move the object towards the target position
    objectRigidbody.MovePosition(Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * lerpSpeed));
    }
    }
    You're welcome :)

    • @pixitales5017
      @pixitales5017 10 หลายเดือนก่อน

      You skip all of that with no jittering at all by adding this when grab object: transform.parent = objectGrabPointTransform; but u might have to make object rigidbody to kinematic temporary if u add collision.

  • @molnarmisel6751
    @molnarmisel6751 5 หลายเดือนก่อน

    Hi! Thank you for doing videos i wanted always lert programming, and now i have a chance thaks you.
    i thinking a lot about how coud i expand this code to have some king of inventory , where i can toggle trougt items, that are in my hand, if you have time , maybe coud show us a very simpe version of script.
    If not its oke, but i thought i have to aks it 🙂.
    thanks lot.....
    lg

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 หลายเดือนก่อน

      In theory you would just destroy the object in the world and add it to some kind of Inventory List.
      Then removing from the inventory you would spawn it in the world in front of the player pre-grabbed
      I made an inventory a long time ago here unitycodemonkey.com/video.php?v=2WnAOV7nHW0
      unitycodemonkey.com/video.php?v=fxaDBE71UHA

    • @molnarmisel6751
      @molnarmisel6751 5 หลายเดือนก่อน

      Thank you! I will make it.

  • @rambro5237
    @rambro5237 2 ปีที่แล้ว

    is there any tips how to plan or design before starting coding the project , bcoz i stuck in-between because of poor planning and gave up the project

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Design enough until you feel comfortable with the project, that's about it, that level will differ from person to person. Some people like an extremely high level design, others like a extremely detailed design. Personally I'm somewhere in the middle, I like to design with quite a bit of detail but not implementation detail, so I design what mechanics I'm going to need, but don't worry too much about how I'm going to implement them unless it's a core part of the design (like the Actions in my TBS course game)
      And the best tip of all is just experience, so just keep at it, keep making games and over time you will get better at design and pre production.

    • @rambro5237
      @rambro5237 2 ปีที่แล้ว +1

      @@CodeMonkeyUnity Thanks for replying.

  • @infamousprogrammer
    @infamousprogrammer ปีที่แล้ว

    how could one do an inventory using this? Like if I have a cupcake grabbed, and If I grab another one, I want the previous cupake to be in my inventory, and I can choose which cupcake to equip by using the numbers on the keyboard

  • @scottrussell8379
    @scottrussell8379 ปีที่แล้ว

    Once clicking to pick up the object, instead of constantly moving the object via FixedUpdate to keep the object aligned with the player/camera, would it be easier to change the object's parent via SetParent to player/camera?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว +1

      That would only be valid if you don't want to use physics while holding the object. If you place a Rigidbody as a child or an object that is not using physics it's going to behave weirdly.
      Also changing the parent can sometimes cause very strange behaviour, depending on how your game is setup. So perhaps that's a valid option and perhaps not.

  • @pranaysinghsengar5215
    @pranaysinghsengar5215 ปีที่แล้ว

    Hey can u please provide video link that how to make first person and third person controller ??

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      I recommend looking into the Starter assets unitycodemonkey.com/video.php?v=jXz5b_9z0Bc

  • @Survivor_Shelter
    @Survivor_Shelter 7 หลายเดือนก่อน

    How can I make it so that when I pick up an object, it is fixed at the desired point, and when I drop it, I can push it with my feet???

  • @deheane
    @deheane ปีที่แล้ว

    How could I bump the objects so they don't cross with the other objects in the scene (the walls and the floor)?

  • @hawkgamedev
    @hawkgamedev 2 ปีที่แล้ว +1

    Me likey.

  • @theattic0098
    @theattic0098 2 ปีที่แล้ว +1

    I've tried a lot of tutorials like this, and I've always run into the same two problems. For me, sometimes the objects with randomly start spinning uncontrollably and start jittering. I've also had to deal with the object clipping into the floor and player. I was wondering how I could fix these issues.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      Did you disable gravity upon picking up the object? Did you experiment with making it kinematic? Maybe try manually rotating the object or adding angular drag

    • @Geckotr
      @Geckotr ปีที่แล้ว

      Only turning on the kinematic stops the jittering but when you do it, objects don't fall and push other objects. Is there a way to do this without rb? Physics system of Unity is very unstable@@CodeMonkeyUnity

    • @jbear40
      @jbear40 7 หลายเดือนก่อน

      A year late, but the best way is to change MovePosition to Move() and add in a lerp for quaternion rotation, and do the same thing for the position. Then on the rigidbody make sure the player layer is not affecting the rigidbody. And there ya go, smooth, supermarket simulator movement

  • @OddKidToons
    @OddKidToons 2 ปีที่แล้ว

    Okay, I got a hard one for you. haha. How can I pick up an AI navmesh root motion driven enemy and carry and throw them? Like in Mario. an have them right themselves after hitting the ground and go back to normal. unless they are dead. In my game I need to be able to pick up pets and throw them platform to platform.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      As long as you don't throw them outside the NavMesh everything should work fine, disable the NavMeshAgent when picking up, re-enable when they touch the ground

    • @OddKidToons
      @OddKidToons 2 ปีที่แล้ว

      @@CodeMonkeyUnity Thanks for the fast reply. I am doing that, through events. booling off and on. But I am ending up with some weird results. Like every time I mick them up they get farther away from me. drive.google.com/file/d/1U9T9EfljEjzLj3lkyn3lFCtUCuSnRK3a/view?usp=sharing
      Here is a video of it.

  • @masonmiller7920
    @masonmiller7920 2 ปีที่แล้ว +1

    I keep getting two errors, one is "No overload for method 'grab' takes 1 arguements"
    and also " 'ObjectGrabbable' does not contain a definition for 'Drop' and no accessible extension method 'Drop' accepting a first argument of type
    ObjectGrabbable' could be found."
    Please help.

    • @YobukoGames
      @YobukoGames ปีที่แล้ว

      Did you end up working this out?

  • @sswt3796
    @sswt3796 2 ปีที่แล้ว

    hi CM.. gr8 video.. I need help..
    I am using unity's new input system, and added an "Aim" input with "Pass through" using right mouse click (as shown in ur TPS video). And i am using this input to grab/drop objects. But it doesn't work like a input key as you have shown here.
    It grabs & drops at the same time.
    how to solve it.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      What event are you listening to? Maybe you're listening to both Started and Performed so it triggers the logic twice which picks it up and drops it

  • @Guidelli_art
    @Guidelli_art 2 ปีที่แล้ว

    I loved the video, but I have a strange bug, if I put the item under the player and jump, it identifies the object and jumps infinitely, as if the catchable object was the ground or something, I'm new to unity, how would i handle it?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว +1

      You can check if the object is under the player and if so teleport it outside the player collider. Use the forward direction and ignore the Y and push it in that direction

  • @mimic8942
    @mimic8942 ปีที่แล้ว

    I know I'm a little late but is there a way of increasing the objects momentum when holding it so that when i drop it, I can throw it?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      You can keep track of the players movement vector and when pressing the Drop button you apply AddForce to the object with the movement vector.

    • @canertwo
      @canertwo ปีที่แล้ว

      I just made this, if you still have difficulties let me know.

  • @elcolgaodeturno485
    @elcolgaodeturno485 ปีที่แล้ว

    Hi, i have a big problem. When i pick up an object their scale changes, making more big o more little. Any idea whats happening?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Are you changing the object parent instead of just moving it? If you parent it to something and then modify the scale of the parent the child will also scale

  • @mattg1345
    @mattg1345 4 หลายเดือนก่อน

    How can this be implemented using the not so new input system

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 หลายเดือนก่อน

      Add the Key actions to your input action asset and listen to the performed event th-cam.com/video/Yjee_e4fICc/w-d-xo.html

  • @kinda_history_nerd
    @kinda_history_nerd ปีที่แล้ว

    I had a question. Why do you make so many scripts? Is it necessary? Or is it for code readability?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Yes for code readability. Each class should do one thing and one thing only. In most cases having multiple small classes will be easier to understand than a single giant class.

  • @antonorlov8838
    @antonorlov8838 2 ปีที่แล้ว

    How do you manage with infinite shifting the player controller up, if move the picking object under the player?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      You could disable the collider on the object for a tiny amount of time when picking it up. Perhaps just disable that ability, if the object is exactly beneath the player dont pick it up

    • @antonorlov8838
      @antonorlov8838 2 ปีที่แล้ว

      @@CodeMonkeyUnity But when the object already picked up, and player could move it around, then if player move the object under itself, and don't release the pick up button, then the object's collider will shift the player up, then we shift the object to match the grab distance, then again object shift the player up and so on. If I turn off object's collider, then it will not collider with other object, but I want it to. Ofcourse I can move the object to another layer, that wouldn't collide with player, but I don't like this, because then I have to use this layer for any grabbable objects. Maybe there is a better way?

  • @someone3541
    @someone3541 ปีที่แล้ว

    It detects its trying to be picked up but its not moving I added a rigid body and the camera point thing

  • @avokado3154
    @avokado3154 10 หลายเดือนก่อน

    how can I make sure that the player does not fly by standing on an object picked up by him?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  10 หลายเดือนก่อน

      You could disable collision between the object and the player collider, look at the physics collision matrix

  • @NowLedgeIO
    @NowLedgeIO 9 หลายเดือนก่อน +1

    school ❌code monkey✔

  • @eternal___official
    @eternal___official 2 ปีที่แล้ว

    Help: i get "NullReferenceException: Object reference not set to an instance of an object" at the line of "objectGrabbable.Drop();" and i cannot understand why... any ideas?
    It's a bummer cos i this is the only video that really halped me creat the scripts needed for this. The first part of grabbing the object works perfect!
    (PS: it is a 3rd player movement with the object moving on Y above player once they grab it)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Use Debug.Log to find what is null unitycodemonkey.com/video.php?v=5irv30-bTJw
      Maybe you didn't attach the script so GetComponent is returning null
      You can also download the project files

  • @barkmober
    @barkmober 2 ปีที่แล้ว

    I am gonna ask my dad to buy me one of you courses although I am an intemidiate i could always use some help wish me luck :)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      Awesome! Best of luck in your learning journey!

    • @barkmober
      @barkmober 2 ปีที่แล้ว

      @@CodeMonkeyUnity Thank you although my dad refused if I get money i surely will buy your courses

  • @lazougre4229
    @lazougre4229 ปีที่แล้ว

    do you have a git?

  • @sleeplessengineer1450
    @sleeplessengineer1450 5 หลายเดือนก่อน

    I would call that more "over the shoulder" than actually 3rd person.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  5 หลายเดือนก่อน

      That's the same thing, just dependent on offset of the camera, increase the distance and put the offset on 0,0,0 if you want it like Diablo or something

  • @JustMoreAyden
    @JustMoreAyden 3 หลายเดือนก่อน

    Hi, codemonkey! I have an issue where if I pick up an object and try and turn, it doesn't rotate all the way. It just rotates on one sed, but if I got to lets say the left, it won't go there. But, lets say I was facing forward it would be there but then I go left its gone, then i face backward and it goes to where my camera is facing again. Please help :)

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  3 หลายเดือนก่อน

      Hmm not sure I understand, the object doesn't stay in the hold position? That one should always be in front of the player regardless of rotation
      You can download the project files and compare with your own

    • @JustMoreAyden
      @JustMoreAyden 3 หลายเดือนก่อน

      @@CodeMonkeyUnity I figured it out, my player was the problem. I'm not sure why, but it works fine now!

  • @arrow8658
    @arrow8658 ปีที่แล้ว

    Question, how would i make it so that it gets picked up when my mouse button is held down and dropped when its released?

    • @scottrussell8379
      @scottrussell8379 ปีที่แล้ว

      If you use the New Input System, context.performed and context.canceled would be one way to handle this.

  • @zambowastaken
    @zambowastaken 2 ปีที่แล้ว

    does this work only for the first time i pick an object?

    • @zambowastaken
      @zambowastaken 2 ปีที่แล้ว

      because when i drop it and i try to pick it again it doesn t works

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      No there's no limit, sounds like you're probably not clearing the picked up game object field when dropping

  • @chocolyn.yogurt
    @chocolyn.yogurt ปีที่แล้ว

    What do I have to change in the script if I'm using third POV

    • @chocolyn.yogurt
      @chocolyn.yogurt ปีที่แล้ว

      I'm trying to make the player grab what's in front of him. I tried what's shown on the video but it's not working. (Idk if this info is necessary but I have a main camera and another third person camera, I used cinemachine.)

  • @tejasyallatti
    @tejasyallatti ปีที่แล้ว

    I did all the steps and the code works well. Im still facing a issue where the item can only be picked up once and after it is dropped, it fails to be picked again. is there any way i can fix this issue? i love the tutorial btw, short and simple!

    • @tejasyallatti
      @tejasyallatti ปีที่แล้ว

      By adding Debug.Log in the if else statements. It seems that after dropping the item and trying to pick it back up. it fails to check if its null and the else statement is executed.

    • @tejasyallatti
      @tejasyallatti ปีที่แล้ว

      So I played around with the code and found the fix for this issue.
      else //else drop the object
      {
      objPickup.Drop();
      objPickup = null;
      Debug.Log("Dropped");
      }
      I made the objPickup=null in the else statement after drop(). if anybody comes across this issue. here's the solution.
      and thank you again for the tutorial !! :)

    • @bishop6308
      @bishop6308 ปีที่แล้ว

      Thanks, worked for me

  • @darktech1641
    @darktech1641 2 ปีที่แล้ว

    Can you upload unity 3d scripting tutorial

  • @pnka999
    @pnka999 7 หลายเดือนก่อน

    even after using fixed update my objects still jitters

  • @crazyartwithtejas2334
    @crazyartwithtejas2334 ปีที่แล้ว

    Plz tell me the line of racast Layer mask that is hidden in the video

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      What line?

    • @crazyartwithtejas2334
      @crazyartwithtejas2334 ปีที่แล้ว +1

      @@CodeMonkeyUnity In playerpickupdrop script in private void update if Get keydown keycode.E in the Physics.raycast(playerCameraTransform) line tell me this whole line plz

  • @dani32642
    @dani32642 ปีที่แล้ว

    Hey! i followed the tutorial and i wanted to stop it from randomly rotating in the air. Also when i move forward, the collider of the object stop me from moving. Is there any way to grab and keep the object stable? As if the player physically has it in their hands, example like a flashlight/torch or a weapon.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว +2

      You could disable the Rigidbody when picking up the object, or lock the constraints to make it not rotate

    • @dani32642
      @dani32642 ปีที่แล้ว +1

      @@CodeMonkeyUnity Thank you. Another Question, The item I grab keeps swaying around when i move. How can I make it stay in a fixed position on screen after picking it up?

    • @MrLazyfella
      @MrLazyfella ปีที่แล้ว

      @@dani32642 Try this, In items rigidbody and in Contraints Freeze the rotations.

  • @steelturtletube3193
    @steelturtletube3193 ปีที่แล้ว +1

    I’m having a problem where I can pick up and drop one item but the second one won’t drop. Does anyone have a solution?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Sounds like you're forgetting to reset the variable that stores the holding object

    • @steelturtletube3193
      @steelturtletube3193 ปีที่แล้ว

      Thank you. I fixed it

  • @mug4621
    @mug4621 ปีที่แล้ว

    um when İ press E when i look to void it pauses my game or kicks me idk why?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      Add some Debug.Log to see what your code is doing, perhaps you're picking up the player itself?

  • @jasc467
    @jasc467 ปีที่แล้ว

    I used the same script as you did and followed all the steps, for some reason i still cant make it do anything even though there are no errors and the code is just fine, could you help?

    • @jasc467
      @jasc467 ปีที่แล้ว

      I know i am way late to comment thogh

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว

      You need to first identify what exactly isn't working, are you not getting input? Is the raycast not hitting anything? Is the object being grabbed but not following? Add some Debug.Log to see where the logic is stopping

  • @julianw3947
    @julianw3947 ปีที่แล้ว

    The object glides through wall even if i turned off Is Kinematic

  • @invormativ
    @invormativ ปีที่แล้ว

    at 3:56 is a part of the code missing, what is there?

  • @blockyboi942
    @blockyboi942 4 หลายเดือนก่อน

    on your site when i click validate email then go back it keeps saying im not validated. so i cant get the files....

    • @blockyboi942
      @blockyboi942 4 หลายเดือนก่อน

      also, how im i able to unload all of the scripts

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  4 หลายเดือนก่อน

      Try logging out and back in again

    • @blockyboi942
      @blockyboi942 4 หลายเดือนก่อน

      @@CodeMonkeyUnity I already tried that

  • @jonasmostrom9636
    @jonasmostrom9636 2 ปีที่แล้ว

    I am trying to add a prompt so I can see if an item can be picked up but nothing I do seems to work. Does anyone have any tip?

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  2 ปีที่แล้ว

      You just need to run the same Raycast logic to see if the item is grabbable, run that logic all the time and have a UI element listen to when the mouse is pointing at nothing or something that can be grabbed.
      I made a similar UI element in the Interact with NPCs video unitycodemonkey.com/video.php?v=LdoImzaY6M4

  • @lazougre4229
    @lazougre4229 ปีที่แล้ว

    plz I want the code without signing in plz

  • @Blessindisguise
    @Blessindisguise ปีที่แล้ว

    For some reason i can't release object after pressing E again. I can only pick it up.

    • @CodeMonkeyUnity
      @CodeMonkeyUnity  ปีที่แล้ว +1

      Add some Debug.Log to see what your code is doing, maybe you're constantly running the same pick up code

    • @Blessindisguise
      @Blessindisguise ปีที่แล้ว

      @CodeMonkeyUnity okay thank you, I will say. I attached another object to the same object, so maybe that's the other issue as well.

    • @Blessindisguise
      @Blessindisguise ปีที่แล้ว

      I added a cube and it's the same thing but I have a repeated error of 999+ of: "NullReferenceException: Object reference not set to an instance of an object" what could be causing that? and is that part of the problem?@@CodeMonkeyUnity