How To Pick & Drop Physics Objects like Karlson | Unity

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

КОМЕНТАРІ • 104

  • @Boxply
    @Boxply  Рік тому +5

    If you have any issues whatsoever (or just want to leave a commendation), feel free to let me know here in the comment section.

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

      In your script, you have set the line renderer position to "this.transform.position". But it will be better and it will have no more bug if you set it to "applicationPoint.position", line 115 in the DrawRope void.
      I'm working on a game like karlson, and so I used your script, I will named you in my last video if you see any trouble

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

      Thanks! And if that works better than go all for it! Good luck on your game

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

      Can you make an updated version for unity 5?

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

      i want to make it when E is pressed...

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

      How would i make it so when you press a button, say F, it freezes in the air?

  • @OrangeVoidDev
    @OrangeVoidDev 21 день тому +1

    Uh... the cube just dissapears when i play, but is still there in the editor

  • @Aperture_dev
    @Aperture_dev 7 днів тому

    i have a strange bug where when i hit play, the camera is separated from my player, causing it to move weird.

  • @alkungfu
    @alkungfu 9 місяців тому +2

    It isnt working at all

    • @Boxply
      @Boxply  4 місяці тому +1

      Can you give me a more detailed explaination of the problem you're having? I highly recommend testing this in a new scene and then slowly testing the features with your current game if it causes issues

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

    Brilliant. Grabbing Works like a Charm

  • @imagine-existing_not-me
    @imagine-existing_not-me Рік тому +3

    every time i add the line renderer to the LIneRendererLocation it teleports away and when you try to move it it changes the transform numbers but doesn't move how do i fix this?

    • @ilizzium1241
      @ilizzium1241 5 місяців тому

      use world space - change

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

    where to add camera plane code?

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

      I stated in the video, you don't add it. It runs without addition. It's a calculation script. It runs without being placed onto any object. We reference it to get the coords of where to hang the object from

  • @lukewerni1
    @lukewerni1 4 дні тому

    Hey, so whenever I drag the cube to near to me (the player) I have the ability to fly. I thought about adding a layer to the player and then say that the player layer cannot collide with the interactable. But then I could walk thorugh the interactable while not grabbing it. I mean I could change the layer in the script but do you have a better solution?

  • @blockyboi942
    @blockyboi942 Місяць тому

    CAN SOMEONE PLEASE HELP ME!!!!!!!! It keeps saying jointdrivemode is no longer supported. and its on 2022 editor⚠⚠⚠

  • @imagine-existing_not-me
    @imagine-existing_not-me Рік тому +1

    Doesn't work it says the spring joints are outdated or something and btw if you do it in a new project then how do you move/look around?

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

      Just get Dani's movement script. He has a video on his channel

  • @hugodanielvalladoliddaumas7073

    help! it says that joint drive mode mode is obsolete on the Rigidbody script line 90

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

      Ah. Obsolete. Does the code still run? Maybe its an issue with the unity version. There should be an updated replacement for joint drive mode in the newer versions then, i suggest you use that

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

    GOOD TUTORIAL BOIII

  • @ilizzium1241
    @ilizzium1241 5 місяців тому

    Whose code doesn't work? I rewrote it. write to me and I’ll tell you what to fix

  • @hugodanielvalladoliddaumas7073

    also, the line isnt tocuhing at all the object im holding, how can i fix this?

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

    help
    NullReferenceException: Object reference not set to an instance of an object
    DragRigidBody.HandleInputEnd (UnityEngine.Vector3 screenPosition) (at Assets/DragRigidBody.cs:58)
    DragRigidBody.OnMouseUp () (at Assets/DragRigidBody.cs:23)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

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

      You probably didn't set the tags and etc right.

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

    i want to make it when E is pressed...

  • @AdamMohamed-jq8ff
    @AdamMohamed-jq8ff Рік тому +1

    its not working with me ( I use new input Systm )
    can I get it work ? I did everything as u but the line is just freezing in ground and it appears if I didnt click anything I tried it in oldeer version and it worked the proplem is from version or input system ? :)

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

      Probably input system. It should work fine with newer versions

  • @VojtaGaming25
    @VojtaGaming25 11 місяців тому +1

    is there a way to make this work with the "E" button because i have my shooting on the left mouse button
    thanks in advance
    great video!

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

      You could modify the code and change the input within it to E. That should be self explanatory. But I'm not sure if there's a function or call for E specifically. You could just put it all in an IF E IS PRESSED Condition then run it unconditional of the left click

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

    I need help, the object are just gliding after I touch them, how do i stop it?

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

      Gliding how? I don't understand the situation here.
      Make sure your object has a rigid body and a collider set up just as shown in the video
      Also, make sure that you have the scripts installed. Both of them in the same folder
      If the problem persists. Try it in a new scene & see what ticks (Just set up a character controller by using Dani's tutorial if you want the same scene as me)

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

      @@Boxply thanks but i figured it out myself i just took away the physics material from the ground.
      Btw do you know a wall walking tutorial that works with danis script?

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

      Glad it worked!
      I have link to a tutorial that does work like a charm on Dani's script. It is made over dani's script.
      ua-cam.com/video/Ryi9JxbMCFM/v-deo.html
      Hope this helps

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

      @@Boxply Thank you❤

  • @munyunu
    @munyunu 6 місяців тому

    Awesome!!

  • @hugodanielvalladoliddaumas7073

    is there anyway I can trigger it with right click?

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

      Your have to go into the script and change the input key for that.
      Input.GetKey
      Something like that & change it to whatever the value is for right click or mouse buttob

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

      @@Boxply its not letting me change from onmousedrag system to a normal input system, the trail line is not following the object im dragging

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

      Ohh.
      On MouseDrag only works for left click.
      You might have to set up a custom function replicating onmousedrag but for the left key

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

      @@Boxply ty!! ill try!

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

      Gl!

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

    The line looks weird when u move (fast ?), Did u put that line rendering thing to LateUpdate ?

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

      Yeah, I did put in on late update. For me it works completely fine as shown in the video. Have you tried it in an empty project?
      Perhaps some settings are messed up

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

      @@Boxply at 4:46 i guess

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

    It doesn't work with my ragdoll character

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

      You probably need to add a new tag to the script. An extra tag/layer that can be picked and dropped specifically for the ragdoll

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

    How to make pickup drop system for my mobile game

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

      Is it 3d? If it's 3d just replace the mouse down functions for input from touch

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

      @@Boxply I am beginner can you please make a tutorial video please

  • @user-zp1dx7un4h
    @user-zp1dx7un4h Рік тому

    the "JointDriveMode" is no longer supported in DragRigidbody script

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

      Not sure if you've fixed it by now, but incase anyone else is looking: changing any of the "joint.xDrive = NewJointDrive (force, damping);" Into: "joint.xDrive = new JointDrive(force, damping);" Seems to fix it.

    • @user-zp1dx7un4h
      @user-zp1dx7un4h Рік тому +1

      @@Raumfist thanks man, but I gave up on unity in general :)

  • @Sproute-RL
    @Sproute-RL 5 місяців тому

    first: when i drag it goesa always to the corner of the object
    second: i can fly

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

      What's your scene looking like right now? Do you have the tags and stuff set properly?

    • @Sproute-RL
      @Sproute-RL 4 місяці тому

      @@Boxply ya

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

      And. What do you mean by "it always goes to the corner of the object?" The line renderer?

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

      I think the flight part may have to do with your movement controller?

    • @Sproute-RL
      @Sproute-RL 4 місяці тому

      @@Boxply b ecause u use the gameobject posotion the position is automatiocally at the corner of the object

  • @user-uk7nx4fy3z
    @user-uk7nx4fy3z 7 місяців тому

    doesnt work with ragdolls

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

      Make sure you add a tag/layer for the ragdoll that will allow it to be dragged. Perhaps change its layer/tag the moment the char dies and turns to a ragdoll

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

    What's the "Camera Plane" for?

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

      It's a pretty detailed thing but in this circumstance, simply put, it turns the camera view relative to plane

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

    I keep getting the error "NullReferenceException: Object reference not set to an instance of an object". I did everything the same as you did, and I only have one camera. Can you help please?

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

      I suggest that you try this tutorial on an empty/test scene to see if it works on your Unity version (it should). You should then, try to see what difference may be causing issues for u

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

      @@Boxply Okay, I'll try that. Thanks!

  • @dontCallMe..
    @dontCallMe.. 11 місяців тому

    How can i make it work with prefabs

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

      you cant dump ass ur working with online and not prefabs lol

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

      Basically you attach the script to the prefab and give it the specific values and tags. It should work just find

  • @bennysensei4662
    @bennysensei4662 5 місяців тому

    Hi. Im a newbie of that and start to learn Unity. What is your template you using? 3D, VR core, or something? Thanks a lot

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

    Hey loved the video I was just hoping you could link the music you used during the tutorial to my comment

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

      All the music I used is by Context Sensitive on UA-cam. Look him up! Thanks for taking an interest

  • @Dino-tr6cn
    @Dino-tr6cn Рік тому +1

    Hey are u from india ?

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

      Well, No I'm not from India. Though, is my accent like that? Haha

    • @Dino-tr6cn
      @Dino-tr6cn 5 місяців тому

      yea@@Boxply

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

    its great but outdated now so its pretty scuffed

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

      Yeah... My bad. Haven't used unity in a while. I picked it up again just a bit ago and will probably refresh myself soon

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

      @@Boxply good for you! that'll be great i subscribed

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

    it isn't working there is nothing wrong i tested it on a new scene i only have 1 camera i do have the "Interactive" layer set to the object i want to drag it does have a box collider and it has the DragRididbody script and i have the camera plane script and it doesn't work the only thing it says is this
    NullReferenceException: Object reference not set to an instance of an object
    DragRigidbody.HandleInputBegin (UnityEngine.Vector3 screenPosition) (at Assets/DragRigidbody.cs:36)
    DragRigidbody.OnMouseDown () (at Assets/DragRigidbody.cs:21)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
    NullReferenceException: Object reference not set to an instance of an object
    DragRigidbody.HandleInputEnd (UnityEngine.Vector3 screenPosition) (at Assets/DragRigidbody.cs:61)
    DragRigidbody.OnMouseUp () (at Assets/DragRigidbody.cs:26)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
    and i set all of the references
    ok so i changed it and there is only one error first here is the modified code
    using UnityEngine;
    [RequireComponent(typeof(Rigidbody))]
    public class DragRigidbody : MonoBehaviour
    {
    public float force = 600;
    public float damping = 6;
    public float distance = 15;
    public LineRenderer lr;
    public Transform lineRenderLocation;
    Transform jointTrans;
    float dragDepth;
    void OnMouseDown()
    {
    HandleInputBegin(Input.mousePosition);
    }
    void OnMouseUp()
    {
    HandleInputEnd(Input.mousePosition);
    }
    void OnMouseDrag()
    {
    HandleInput(Input.mousePosition);
    }
    public void HandleInputBegin(Vector3 screenPosition)
    {
    var ray = Camera.main.ScreenPointToRay(screenPosition);
    RaycastHit hit;
    if (Physics.Raycast(ray, out hit, distance))
    {
    if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Interactive"))
    {
    dragDepth = CameraPlane.CameraToPointDepth(Camera.main, hit.point);
    jointTrans = AttachJoint(hit.rigidbody, hit.point);
    Debug.Log("Joint Attached");
    }
    }
    lr.positionCount = 2;
    }
    public void HandleInput(Vector3 screenPosition)
    {
    if (jointTrans == null)
    return;
    var worldPos = Camera.main.ScreenToWorldPoint(screenPosition);
    jointTrans.position = CameraPlane.ScreenToWorldPlanePoint(Camera.main, dragDepth, screenPosition);
    DrawRope();
    }
    public void HandleInputEnd(Vector3 screenPosition)
    {
    DestroyRope();
    if (jointTrans != null)
    {
    Destroy(jointTrans.gameObject);
    jointTrans = null; // Set jointTrans to null after destroying the game object.
    Debug.Log("Joint Detached");
    }
    }
    Transform AttachJoint(Rigidbody rb, Vector3 attachmentPosition)
    {
    GameObject go = new GameObject("Attachment Point");
    go.hideFlags = HideFlags.HideInHierarchy;
    go.transform.position = attachmentPosition;
    var newRb = go.AddComponent();
    newRb.isKinematic = true;
    var joint = go.AddComponent();
    joint.connectedBody = rb;
    joint.configuredInWorldSpace = true;
    joint.xDrive = CreateJointDrive(force, damping);
    joint.yDrive = CreateJointDrive(force, damping);
    joint.zDrive = CreateJointDrive(force, damping);
    joint.slerpDrive = CreateJointDrive(force, damping);
    joint.rotationDriveMode = RotationDriveMode.Slerp;
    return go.transform;
    }
    private JointDrive CreateJointDrive(float force, float damping)
    {
    return new JointDrive
    {
    positionSpring = force,
    positionDamper = damping,
    maximumForce = Mathf.Infinity
    };
    }
    private void DrawRope()
    {
    if (jointTrans == null)
    {
    return;
    }
    lr.SetPosition(0, lineRenderLocation.position);
    lr.SetPosition(1, this.transform.position);
    }
    private void DestroyRope()
    {
    lr.positionCount = 0;
    }
    }
    and the error is NullReferenceException: Object reference not set to an instance of an object
    DragRigidbody.HandleInputBegin (UnityEngine.Vector3 screenPosition) (at Assets/DragRigidbody.cs:33)
    DragRigidbody.OnMouseDown () (at Assets/DragRigidbody.cs:18)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)

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

      the camera needs the MainCamera tag to it

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

      it is@@HackingStuffIDontKnow

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

      Sorry for being a bit late but may have to do with the tags on the objects in the scene that you want to pick and drop

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

    What is the CameraPlane script for? I keep getting an error "NullReferenceException: Object reference not set to an instance of an object
    DragRigidbody.HandleInputBegin (UnityEngine.Vector3 screenPosition) (at Assets/DragRigidbody.cs:36)
    DragRigidbody.OnMouseDown () (at Assets/DragRigidbody.cs:21)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)" I have no idea what is going on. Whenever I push an object that has the script, it stretches out and looks really weird. I need help.

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

      Also there is no range. the error runs even when i click from far away

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

      I resolved the stretching problem, but not the other problems

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

      The camera plane script is to be able to get the objects position in 3d view according to it's distance from you and the position of the cursor, else, game doesn't know where to hook the object up. It should work tho. Perhaps one of your scripts is interfering. Try it in an empty scene and see what the issue might be

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

      @@Boxply it says that something is wrong with line 36. I got rid of every script using the mouse0 button. Btw I am using a seperate moveplayer script, not the one dani made. it still says that line 36 has something wrong with it. line 36: var ray = Camera.main.ScreenPointToRay(screenPosition); do you think that its because my camera is named differently than yours? plz respond

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

      Maybe you have multiple cameras and it doesn't know which one to use that's supposed to reference the player camera or the camera the player sees through