How to Pick up and Place objects in Unity P1

Поділитися
Вставка
  • Опубліковано 21 сер 2024

КОМЕНТАРІ • 75

  • @DanWarrioR
    @DanWarrioR Рік тому +2

    Nice video where you can understand all and learn how is it works. Very helpful.

  • @SunnyValleyStudio
    @SunnyValleyStudio  2 роки тому

    Part 2 -> ua-cam.com/video/t-WkP_UyrgU/v-deo.html

  • @lazytocook
    @lazytocook Рік тому +3

    u sound like a good man. many thanks for this and giving us for free.

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому

      Thanks for watching 🙂 I'm doing my best to help others but not all I do is for free. In my opinion everyone should get compensated if they do a good job 👍

  • @Baba-ic4un
    @Baba-ic4un 2 роки тому +2

    Best video for learning Pickup mechanism...I found many videos but this one is the perfect... 😊😊😊

  • @I_wcas
    @I_wcas 7 місяців тому +1

    I love your video, you don't even know how much this video helped me, you deserve more subscribers, views and likes than you have for your extreme effort. Keep going!!

    • @SunnyValleyStudio
      @SunnyValleyStudio  7 місяців тому

      I'm glad that I can help you with my videos 🙂 Thanks a lot for watching! 👍

  • @kaylafortson9236
    @kaylafortson9236 Рік тому +1

    Extremely helpful tutorial, thank you!

  • @deniscooper09
    @deniscooper09 2 роки тому +2

    Thanks for good videos ☺️

  • @hh5559
    @hh5559 8 місяців тому +1

    Used the exact script and followed everything up to 8:00 but it won't highlight a Lantern or pillow I set as 'pickable'.
    Not sure what I'm doing wrong because there's no errors in the scripts and I even assigned the Highlight Script to those models.

    • @SunnyValleyStudio
      @SunnyValleyStudio  8 місяців тому

      If it doesn't highlight the objects you could check 2 things. If you can pick up the object I would check if the material has its emission parameter set - since it makes the object glow. If you can't pick up the object it means that our raycast is not detecting the object. In this case the easiest thing is to debug your code or simply "Debug.log" if something is detected by the raycast or not. It might be too short or just blocked by another object.

  • @ALLmasked
    @ALLmasked 2 роки тому +2

    after learning this by combining sources. i then found this video .... MOTHER! FFFF

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 роки тому

      Hey! I'm doing my best to create tutorials about whole game mechanics. Maybe you will find some other of my series helpful 😉

  • @nikhilbambal5809
    @nikhilbambal5809 Рік тому +2

    I want to drop object in a a specific place in a centre of the place is like a lab device, how can I do that...

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому

      You could have a separate script like a "socket" where you drop the object and if it is colliding with the socket it is auto attached in the correct spot.

    • @nikhilbambal5809
      @nikhilbambal5809 Рік тому +1

      ​@@SunnyValleyStudioCan you make short video on this..or script..

  • @TheKr0ckeR
    @TheKr0ckeR 2 роки тому +1

    Thanks for great video, what would you to instead of press to pick up, hold to pick up

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 роки тому +1

      Thanks!
      All you need is instead of action start a coroutine (maybe show a progress bar) and do the action after the time is up.
      The only additional thing would be to add a *released* action on that button to break from the coroutine if the player let's go of the button too soon.

  • @themaskedman6253
    @themaskedman6253 Рік тому +1

    I tried this but I keep getting this error and I'm not sure what I missed Assets/RaycastPickupDetection.cs(30,35): error CS0246: The type or namespace name 'Highlight' could not be found (are you missing a using directive or an assembly reference?)

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому

      We don't put this script in a separate namespace. It might be an error with the Highlight.cs script. Do check if you don't see any compilation error / is the script names the same as you type it. The most often issue is misspeling the name or an error in the script that prevents it from being compiled. Less often you actually have to add at the tom "using CustomNamespace". I hope it helps!

  • @Paaskedrengen
    @Paaskedrengen 2 місяці тому +2

    Any idea why me item object can go through walls when im holding it?

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 місяці тому +1

      Because we are using Kinematic RB for the item if I am not mistaken. If you make the item to have a Dynamic RB the movement will be jagged but any collision between it and wall will be detected. It is the same problem as you can see in VR games. There is no one simple solution for it. The easiest one is using a dynamic Rigidbody to prevent collision. The most "precise" one is using kinematic RB and coding your own collision reaction - so for example if player tries to push object too far into the wall the Player drops the object (the object stays on the correct side of the wall). Again there are many others so you would have to do a bit of testing / research to find out what works best for you.

    • @Paaskedrengen
      @Paaskedrengen 2 місяці тому

      @@SunnyValleyStudio Thanks for the answer. Yea i would have hoped that this mechanic was the same as we see in example Portal. Not having any success implementing is so far sadly.

  • @nikhilbambal5809
    @nikhilbambal5809 Рік тому +1

    Sir, I have a problem, when I droup object the size of object getting small..

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому

      That is kind of strange. Check the code for any place where we are modifying the scale. It might also happen if you are parenting the object instantiated to some parent object.

    • @nikhilbambal5809
      @nikhilbambal5809 Рік тому +1

      I want to drop object in a specific place in a centre of the place is like a lab device, how can I do that...

    • @nikhilbambal5809
      @nikhilbambal5809 Рік тому +1

      ​​@@SunnyValleyStudioThis fixed..
      I have one more questions..
      Specific place I want to drop the object in centre how can do that..

  • @nunomonteiro9808
    @nunomonteiro9808 Рік тому +1

    Hello, I learned a lot... Thank you. I just have a question. How can I put, for example, on the PickUpSlot a maximum of X number of itemHand I can grab and then using Mouse wheel to change into them? :D

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому

      I'm not quite sure what you mean by that. Usually you just need to write a bit more code to extend the current functionality - like when you know what is selected you can listen to scroll wheel and change some parameter before you press pick up key.

  • @thurasoe3083
    @thurasoe3083 2 роки тому +1

    Is the Unity OOP course going to be available on Udemy?

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 роки тому

      Yeah it is. Here is a link www.udemy.com/course/oop-for-unity-devs/?couponCode=30_OFF

  • @mihaistanciu2487
    @mihaistanciu2487 2 роки тому +1

    Hello. As always very good video. Can you, please, tell us the name of the tool you have on Visual Studio that try to autocomplete the code lines? Thanks.

  • @sheldonchettiar924
    @sheldonchettiar924 Рік тому +1

    thanky

  • @REBELHEADGAMES
    @REBELHEADGAMES 2 роки тому +1

    Hey there I love thr video! Is there any way to put an item to a fixed place? Example: I pick up a vhs tape in one room, and want to put it into a vhs player in the other room.

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 роки тому +1

      Hey!
      The simplest solution to this would be to leave the default "drop" logic and add a trigger collider to the vhsplayer. The vhsplayer could check continuously (or using events to handle swapping items when in range of the collider) in case the player gets close "is the item player is holding a VHS tape?" if so maybe show "press E to use" or if you want to use the same button press add a bool flag that will ignore the default drop logic and instead use some custom logic in vhsplayer update() that check "if drop button was pressed remove the VHS tape from player and play the video"

  • @chocolyn.yogurt
    @chocolyn.yogurt Рік тому +1

    Is this working for third person player? I'm planning to make the player pickup the item that's in front of him

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому

      In First Person you can very easily direct a simple Ray at the object. in 3rd person I would use something like SphereCast / Sphere trigger collider to detect object since it might be much harder for the players to point at the object.
      I mean you can use this method yes but for the sake of having a great experience I would modify the detection to be more forgiving rather than asking you to point exactly at the object. Still it should work.

  • @xdrocky5417
    @xdrocky5417 2 роки тому +1

    Hello I have small problem I did everything as you did except I used “old input system” and it doesnt work I mean it pickups the items but it doesnt drop them I put debug log on it and it doesnt even print that do you know what could be problem. Thanks

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 роки тому +1

      Hey! It should not matter. The logic is *if I am holding something the drop button will drop it*
      I suspect that you may have a bug in your logic. Check your script again mine (github link) or verify if you ex can debug.log when you press the drop button using your setup. Thos kind of bugs are often caused by us messing up the logic behind reading the input and not the code that we write later.
      I hope that helps!

    • @xdrocky5417
      @xdrocky5417 2 роки тому

      @@SunnyValleyStudio I checked if I press Q for drop before I pickup anything it will Debug Log the text but if I pickup and then press it will not work I can send you code

    • @theogagentnate
      @theogagentnate 9 місяців тому

      Same thing is happening to me

    • @theogagentnate
      @theogagentnate 9 місяців тому

      For me it was because the if(inHandItem != null) was too high in my update script. So if I had an item in my hands it would skip the rest of my update

  • @tarabara603
    @tarabara603 Рік тому

    Hi, great video. It definitely helped me with my project. I just have a question. How do I increase the length of the hitRange? I tried increasing the value to 1000 but doesnt change.

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому +1

      If you are asking for the Raycast code insider Player.cs you have to multiply " forward * 1000" since Physics.Raycast takes the origin point and the direction so we need to inscreas the length of the direction vector.
      I hope it helps!

    • @tarabara603
      @tarabara603 Рік тому

      @@SunnyValleyStudio That was exactly what i needed, thanks

  • @Ratos-
    @Ratos- 2 роки тому

    I havent watched this series yet and just want to know if this applies to 2d before i do? thanks.

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 роки тому

      Hey!
      This tutorial will give you an idea of how to structure your code base behind a pickup system but obviously the example is in 3d. For a 2d game you would basically need to modify the Raycast logic to use *Physics2d.Raycast*
      I show how to implement a simple 2d pickup logic in my inventory tutorial (in one of the last parts). You can watch only that part or the whole inventory setup if you are interested. Here is the link to part 18 where I show how to pick up items ua-cam.com/video/ysUb6u08uMo/v-deo.html

  • @ghostarda6355
    @ghostarda6355 Рік тому +1

    hey nice video! but i get a lot of errors like: Assets\Scripts\Player.cs(76,25): error CS0246: The type or namespace name 'InputAction' could not be found (are you missing a using directive or an assembly reference?)
    or: Assets\Scripts\Player.cs(41,12): error CS0246: The type or namespace name 'InputActionReference' could not be found (are you missing a using directive or an assembly reference?)
    can you help me pls?

    • @ghostarda6355
      @ghostarda6355 Рік тому

      and i think its because of this: Assets\Scripts\Player.cs(5,19): error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому

      Hey!
      I think you are missing the new input system package and that is why you have all those errors. Installing it should help!
      Here is how docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Installation.html
      If you have used my starter package it should be included. Sorry if it wasn't!

    • @ghostarda6355
      @ghostarda6355 Рік тому

      @@SunnyValleyStudio oh ok thx but now if i Start unity there is a Tab saying restart unity because native input or something

  • @benzeji9686
    @benzeji9686 4 місяці тому

    Why does the item hang in place and not move behind the character?

    • @SunnyValleyStudio
      @SunnyValleyStudio  4 місяці тому

      Inside the Player script we do "inHandItem.transform.SetParent(pickUpParent.transform, pickableItem.KeepWorldPosition);" which portents the item to our Player character. We also set the items RigidBody to be kinematic inside PickableIte.cs. That is what makes the item follow the player github.com/SunnyValleyStudio/Unity-simple-Pick-Up-system/blob/main/Player.cs#L78

  • @santako2462
    @santako2462 Рік тому

    NullReferenceException: Object reference not set to an instance of an object
    Player.Start () (at Assets/Scripts/HelperScripts/Player.cs:45) does not work as it always gives this error and has the new input system and the version of Unity is 2021.3.16f1 and Input System 1.4.4

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому +1

      NullRef exception means that something is null. At line 45 of Player script we have *useInput* reference. It is assigned in the inspector of the Player.cs ([SerializeField] private InputActionReference interactionInput, dropInput, useInput;)
      Are you sure that you have assigned it there? I think I explain it at 11:35

    • @santako2462
      @santako2462 Рік тому

      @@SunnyValleyStudio Thank you very much, that’s what I needed

  • @lyne.k9780
    @lyne.k9780 3 місяці тому

    Hi how can it be possible to do it with a mixamo character

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 місяці тому

      What do you mean exactly? If you want to have a 3rd person camera with a character animated with Mixamo you would use something like SphereCast or OverlapSphere to detect the object to interact with instead of raycasting from the camera (unless you have an isometric camera and its more convenient ). You would just play the "pick up" animation and use animation events to trigger the pickup logic.
      If you mean FPS + a 3d character the solution would be the same as above.

  • @thelegendarymushroom80
    @thelegendarymushroom80 Рік тому +1

    It won't drop down the item, but I have the exact same code :(

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому +1

      Maybe for some reason the DROP action input is not assigned / is not set correctly in the Player.cs script or in the Input Actions asset where we have assigned keyboard keys to the Drop action?

    • @thelegendarymushroom80
      @thelegendarymushroom80 Рік тому

      @@SunnyValleyStudio I did check it multiple times and it seems fine. But it's like the buttons till won't work :( it's okay tho

  • @GGamess
    @GGamess 2 роки тому

    the build of the game does not work backlight items

    • @SunnyValleyStudio
      @SunnyValleyStudio  2 роки тому

      Building a game is different depending on a platform and the project. Your game might work well in the editor but might require modifications when creating a build. That is why it is useful to try to build the game as soon as the first prototype to avoid major changes.

  • @crz6835
    @crz6835 Рік тому

    the download of the starter project dont work

    • @SunnyValleyStudio
      @SunnyValleyStudio  Рік тому

      Hey! I have just downloaded the project and opened it in Unity 2021.3.1f1 and everything works great!

    • @crz6835
      @crz6835 Рік тому

      @@SunnyValleyStudio No i mean the link dont work, i press the button to download from the drive and dont does nothing, allready tried it with other browser

  • @cheapgamer6909
    @cheapgamer6909 2 місяці тому

    You have link another vdo for pick item for Mobile game like granny if you have then share me i am still waiting