How to Make a Pick up System in UNITY With Rigidbodies [C#] [Unity3D]

Поделиться
HTML-код
  • Опубликовано: 18 дек 2024

Комментарии • 95

  • @Rytech_Dev
    @Rytech_Dev  2 года назад +7

    Please watch the up to date version of this tutorial
    ruclips.net/video/zgCV26yFAiU/видео.html

  • @Paragorax
    @Paragorax 3 года назад +7

    I have to say, well done, ive been through at least 3 other tutorials, all of which failed. but with yours i was finally able to do it! thank you!

    • @couthdragon
      @couthdragon 3 года назад

      can you send me the code i typed it but it did not work so i want to see if i did something wrong

    • @Neepo1220
      @Neepo1220 2 года назад

      Bro same

  • @TheDuccyGaming
    @TheDuccyGaming Год назад

    400th LIKE!!! This tutorial was exactly what I was looking for! TYSM

  • @ivansnav
    @ivansnav 3 года назад

    Yoooo underrated af! Definetely helped newbie me make some clean codes on unity! You deserve more recognition tho

  • @TheDaltonsUk
    @TheDaltonsUk 3 года назад +1

    Best tutorial in a while , good job and thanks :D

  • @Neepo1220
    @Neepo1220 2 года назад

    Thanks for tutorial after like 5 others yours is the only one that worked. Thanks again :D

  • @More_NickMaster
    @More_NickMaster 3 года назад

    My boy Vinnie with those throws!

  • @barrelbrothers6896
    @barrelbrothers6896 2 года назад +1

    Amazing tutorial man! Super easy to follow and he script works perfectly

  • @audiofrank6747
    @audiofrank6747 2 года назад

    Thank you so much !😃

  • @petarashmalaj
    @petarashmalaj Год назад +1

    Go, Vinny, Go! 🤣

  • @fernandodasilva-producoesa1023
    @fernandodasilva-producoesa1023 8 месяцев назад

    Thank you very much, very simple to implement. I now only need to clean my code and see if i can implement this into an interface or a different function.

  • @benymona-moke9419
    @benymona-moke9419 2 года назад

    Amazing helped so much

  • @onlyrxtro7059
    @onlyrxtro7059 5 месяцев назад +1

    Is it a way to make it to where only I can pick it up and nobody else able to touch it even when I drop it

  • @aquafina2on217
    @aquafina2on217 3 года назад

    super helpful thank you so so much

  • @edij100
    @edij100 6 месяцев назад +1

    Hello! I dont know if you will see this, but how do i make it... Not jittery?

  • @PP-qw3yr
    @PP-qw3yr 3 года назад

    thank you, this is the only video works in RUclips

  • @nodis-l9l
    @nodis-l9l 3 дня назад

    Thanks for this tutorial, but it's really jittery, do you think there is a way to fix that?

  • @brylinx1451
    @brylinx1451 3 года назад

    Great tutorial bro

  • @1ks_SPOT
    @1ks_SPOT 2 года назад

    thanks you are amazing teacher. Good luck

  • @mate20xg
    @mate20xg 3 года назад

    Thx for this tutorial its very good

  • @fagnersales532
    @fagnersales532 2 года назад

    Awesome!

  • @PhoneUser89
    @PhoneUser89 Год назад

    Underrated

  • @big03145
    @big03145 Год назад

    hey bro! what if i pickup a object and press r to delete it in my hand

  • @thefirstblank607
    @thefirstblank607 Год назад

    How do i play an animation if i press Pickup and the Objekt is in range?

  • @duyphatnguyenmai9853
    @duyphatnguyenmai9853 2 года назад

    amazing

  • @PowerGame422
    @PowerGame422 2 года назад

    Why in my pickup layer doesn't show "pickup"

  • @ehansytaxian
    @ehansytaxian 2 года назад

    Poor Vinne Cant Breath 1:48

  • @nayefmsh8274
    @nayefmsh8274 2 года назад

    I bet you were laughing whenever you failed recording the intro about vinny
    I would sure have if I were you

  • @hyperadoi
    @hyperadoi 3 года назад

    bro where i writed CurrentObjectCollider.rotation = Hand.rotation; they showed me an error where they say "Assets\Pickup.cs(43,36): error CS1061: 'Collider' does not contain a definition for 'rotation' and no accessible extension method 'rotation' accepting a first argument of type 'Collider' could be found (are you missing a using directive or an assembly reference?)" what is the problem?

    • @Rytech_Dev
      @Rytech_Dev  3 года назад +1

      the type Collider does not have the variable rotation. So do CurrentObjectCollider.transform.rotation

  • @zombboi
    @zombboi 3 года назад

    Is there a way to do it with Tags? All of my objects need to be on the Ground layer to work properly. Thanks in advance!

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      You can use GameObject.CompareTag(); function. Get rid of the extra layermask parameter on the raycast and in the if statement for the raycast use the comparetag function.

  • @fakruladly1118
    @fakruladly1118 10 месяцев назад

    How fix jitter Bro?Please Help me!

  • @recon4697
    @recon4697 3 года назад

    great video!
    One question though how can I make it so that it's smooth whenever I move my player Camera

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      For all the pickup objects in your game set their rigidbody interpolation mode to interpolate.

    • @recon4697
      @recon4697 3 года назад

      @@Rytech_Dev worked fine, still a bit jittery though

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      @@recon4697 I guess another thing you could try is putting your movement code in LateUpdate or fixedupdate functions alongside with the interpolation on the rigidbody.

    • @recon4697
      @recon4697 3 года назад

      @@Rytech_Dev didn't work, it only made my movement delayed. Thanks for the help though and keep up the great work!
      although if you could think of anything else I'd appreciate it.

    • @recon4697
      @recon4697 3 года назад

      @@Rytech_Dev Also I tried multiplying Time.deltaTime by hand.position just to see what would happen, and the jittery part was fixed but the position was set to the cameras position.

  • @schnippeldifit7805
    @schnippeldifit7805 2 года назад

    the maaatrix

  • @troisot1107
    @troisot1107 3 года назад

    Could you make stealth game tutorial ?

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      That would be pretty fun. I will start working on it (:

  • @ryvenenennnn
    @ryvenenennnn 2 года назад

    thanks

  • @legend3305
    @legend3305 3 года назад +1

    0:49 since when was boxes sepheres ??????????????????
    /:0
    EDIT: really cool tho

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      Vinnie's boxes are odd...

  • @Rytech_Dev
    @Rytech_Dev  3 года назад +3

    Vinnie

  • @joeyestrada9071
    @joeyestrada9071 Год назад

    This is not working for me whatsoever. I feel like I've set something up wrong...

  • @calisthenicswithandrew7183
    @calisthenicswithandrew7183 2 года назад

    It's a perfect tutorial, but can you please make a tutorial on how to resolve the glitchy thing at the object when we move?

    • @calisthenicswithandrew7183
      @calisthenicswithandrew7183 2 года назад

      And yea, I know you made a updated tutorial but I want the character to hold the objects in his hand, not to move objects in the air, thank you!
      Also, I like your content

  • @smileplz3345
    @smileplz3345 Месяц назад

    its jittery FIX PLZ

  • @couthdragon
    @couthdragon 3 года назад

    ok i think i did something wrong or this just does not work in 2020.3 it says there are complier errors here is the code i use what did i do wrong i know that this is not the finished code it is from when he first when back to the game
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class pickupclass : MonoBehaviour
    {
    [SerializeField] private LayerMask PickupLayer;
    [SerializeField] private Camera PlayerCamera;
    [SerializeField] private float PickupRange;
    private Rigidbody CurrentObjectRigidbody;
    private Collider CurrentObjectCollider;
    // Update is called once per frame
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.E))
    {
    Ray Pickupray = new Ray(PlayerCamera.tranform.postion, PlayerCamera.transfom.forward);
    if (Physics.Raycast(Pickupray, out RaycastHit hitInfo, PickupRange, PickupLayer))
    {
    if (CurrentObjectRigidbody)
    {
    }
    else
    {
    CurrentObjectRigidbody = hitInfo.rigidBody;
    CurrentObjectCollider = hitInfo.collider;
    CurrentObjectRigidbody.isKinematic = true;
    CurrentObjectCollider.enabled = false;
    }
    }
    }

    }
    }

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      Whats the error that you are getting

    • @couthdragon
      @couthdragon 3 года назад

      @@Rytech_Dev it just says complier errors

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      @@couthdragon does the name of your class match the .cs file?

    • @couthdragon
      @couthdragon 3 года назад

      @@Rytech_Dev yeah

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      @@couthdragon If it just says "compiler errors" and doesn't give you any further information, just start a fresh new project.

  • @zilvanilab7219
    @zilvanilab7219 3 года назад

    can u send me the full script plz?

    • @hareyold3460
      @hareyold3460 2 года назад +5

      i know this is really late and youve probably moved on but here:
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class PickupClass : MonoBehaviour
      {
      [SerializeField] private LayerMask PickupLayer;
      [SerializeField] private Camera PlayerCamera;
      [SerializeField] private float ThrowingForce;
      [SerializeField] private float PickupRange;
      [SerializeField] private Transform Hand;
      private Rigidbody CurrentObjectRigidbody;
      private Collider CurrentObjectCollider;
      void Update()
      {
      if (Input.GetKeyDown(KeyCode.E))
      {
      Ray Pickupray = new Ray(PlayerCamera.transform.position, PlayerCamera.transform.forward);
      if (Physics.Raycast(Pickupray, out RaycastHit hitInfo, PickupRange, PickupLayer))
      {
      if (CurrentObjectRigidbody)
      {
      CurrentObjectRigidbody.isKinematic = false;
      CurrentObjectCollider.enabled = true;
      CurrentObjectRigidbody = hitInfo.rigidbody;
      CurrentObjectCollider = hitInfo.collider;
      CurrentObjectRigidbody.isKinematic = true;
      CurrentObjectCollider.enabled = false;
      }
      else
      {
      CurrentObjectRigidbody = hitInfo.rigidbody;
      CurrentObjectCollider = hitInfo.collider;
      CurrentObjectRigidbody.isKinematic = true;
      CurrentObjectCollider.enabled = false;
      }
      return;
      }
      if (CurrentObjectRigidbody)
      {
      CurrentObjectRigidbody.isKinematic = false;
      CurrentObjectCollider.enabled = true;
      CurrentObjectRigidbody = null;
      CurrentObjectCollider = null;
      }
      }
      if (Input.GetKeyDown(KeyCode.Q))
      {
      if (CurrentObjectRigidbody)
      {
      CurrentObjectRigidbody.isKinematic = false;
      CurrentObjectCollider.enabled = true;
      CurrentObjectRigidbody.AddForce(PlayerCamera.transform.forward * ThrowingForce, ForceMode.Impulse);
      CurrentObjectRigidbody = null;
      CurrentObjectCollider = null;
      }
      }
      if (CurrentObjectRigidbody)
      {
      CurrentObjectRigidbody.position = Hand.position;
      CurrentObjectRigidbody.rotation = Hand.rotation;
      }
      }
      }

    • @zilvanilab7219
      @zilvanilab7219 2 года назад

      @@hareyold3460 thank you.

  • @DeletedAccount385
    @DeletedAccount385 3 года назад

    do you remember? Next is choping trees😺😁

  • @Gowy_YT
    @Gowy_YT 2 года назад

    TSYM!!!

  • @dr.albitros4242
    @dr.albitros4242 2 года назад

    I personaly use my own metod. It's kinda different than your's, but i think it's cool. But still, this tut is cool

  • @DanRobart
    @DanRobart Год назад

    Bro the boxes are named sphere 🤣🤣🤣🤣🤣🤣

  • @mangomctango1802
    @mangomctango1802 2 года назад +1

    it says some where in my code there is a misplaced ";" but i can't find it.
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class pickup : MonoBehaviour
    {

    [SerializeField] private LayerMask PickupLayer;
    [SerializeField] private Camera PlayerCamera;
    [SerializeField] private ThrowingForce;
    [SerializeField] private float PickupRange;
    [SerializeField] private Transform Hand;
    private Rigidbody CurrentObjectRigidbody;
    private Collider CurrentObjectCollider;
    void Update()
    {
    if(Input.GetKeyDown(KeyCode.E))
    {
    Ray Pickupray = new Ray(PlayerCamera.transform.position, PlayerCamera.transform.forward);
    if(Physics.Raycast(Pickupray, out RaycastHit hitInfo, PickupRange, PickupLayer))
    {
    if(CurrentObjectRigidbody)
    {
    CurrentObjectRigidbody.isKinematic = false;
    CurrentObjectCollider.enabled = true;
    CurrentObjectRigidbody = hitInfo.rigidbody;
    CurrentObjectCollider = hitInfo.collider;
    CurrentObjectRigidbody.isKinematic = true;
    CurrentObjectCollider.enabled = false;
    }
    else
    {
    CurrentObjectRigidbody = hitInfo.rigidbody;
    CurrentObjectCollider = hitInfo.collider;
    CurrentObjectRigidbody.isKinematic = true;
    CurrentObjectCollider.enabled = false;
    }
    return;
    }

    if(CurrentObjectRigidbody)
    {
    CurrentObjectRigidbody.isKinematic = false;
    CurrentObjectCollider.enabled = true;
    CurrentObjectRigidbody = null;
    CurrentObjectCollider = null;
    }
    }

    if(Input.GetKeyDown(KeyCode.Q))
    {
    if(CurrentObjectRigidbody)
    {
    CurrentObjectRigidbody.isKinematic = false;
    CurrentObjectCollider.enabled = true;
    CurrentObjectRigidbody.AddForce(PlayerCamera.transform.forward * ThrowingForce, ForceMode.Impulse);
    CurrentObjectRigidbody = null;
    CurrentObjectCollider = null;
    }
    }

  • @madhatter2497
    @madhatter2497 3 года назад +1

    I finished the whole thing but at the end the script didn't work and I barley understand why it is happening here is the code
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class PickUp : MonoBehaviour
    {
    [SerializeField] private LayerMask PickupLayer;
    [SerializeField] private Camera PlayerCamera;
    [SerializeField] private float PickupRange;
    [SerializeField] private Transform Hand;
    [SerializeField] private float force;
    private Rigidbody rb;
    private Collider Collider;

    // Update is called once per frame
    void Update()
    {
    if (Input.GetKeyDown(KeyCode.E))
    {
    Ray Pickupray = new Ray(PlayerCamera.transform.position, PlayerCamera.transform.forward);
    if (Physics.Raycast(Pickupray, out RaycastHit hitinfo, PickupRange, PickupLayer))
    {
    if (rb)
    {
    rb.isKinematic = false;
    Collider.enabled = true;
    rb = hitinfo.rigidbody;
    Collider = hitinfo.collider;
    rb.isKinematic = true;
    Collider.enabled = false;
    }
    else
    {
    rb = hitinfo.rigidbody;
    Collider = hitinfo.collider;
    rb.isKinematic = true;
    Collider.enabled = false;
    }
    return;
    }
    }
    if (rb)
    {
    rb.isKinematic = false;
    Collider.enabled = true;
    rb = null;
    Collider = null;

    }
    if (Input.GetKeyDown(KeyCode.Q))
    {
    if (rb)
    {
    rb.isKinematic = false;
    Collider.enabled = true;
    rb = null;
    Collider = null;
    rb.AddForce(PlayerCamera.transform.forward * force, ForceMode.Impulse);
    }
    }
    if (rb)
    {
    rb.position = Hand.position;
    rb.rotation = Hand.rotation;
    }

    }
    }

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      What error are you getting?

    • @madhatter2497
      @madhatter2497 3 года назад

      @@Rytech_Dev Nope

    • @Rytech_Dev
      @Rytech_Dev  3 года назад

      @@madhatter2497 I wouldn't worry too much because I am going to make a redo of this tutorial.

    • @madhatter2497
      @madhatter2497 3 года назад

      @@Rytech_Dev Nice

    • @madhatter2497
      @madhatter2497 3 года назад

      @@Rytech_Dev I just found a error in it UnassignedReferenceException: The variable PlayerCamera of PickUp has not been assigned.
      You probably need to assign the PlayerCamera variable of the PickUp script in the inspector.
      PickUp.Update () (at Assets/Scripts/PickUp/PickUp.cs:24)
      idk what this even means and I have gone though the script