How To Pick & Drop Physics Objects like Karlson | Unity

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

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

  • @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.. 11 หลายเดือนก่อน

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

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

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

  • @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 7 หลายเดือนก่อน

      use world space - change

  • @thesweetgamer24
    @thesweetgamer24 วันที่ผ่านมา +1

    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)
    whats this

  • @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

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

    Brilliant. Grabbing Works like a Charm

  • @F40styDev
    @F40styDev 2 หลายเดือนก่อน +1

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

  • @Aperture_dev
    @Aperture_dev 2 หลายเดือนก่อน

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

  • @VojtaGaming25
    @VojtaGaming25 ปีที่แล้ว +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  9 หลายเดือนก่อน

      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

  • @lukewerni1
    @lukewerni1 2 หลายเดือนก่อน

    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?

  • @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  7 หลายเดือนก่อน

      Probably input system. It should work fine with newer versions

  • @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  9 หลายเดือนก่อน

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

  • @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

  • @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.
      th-cam.com/video/Ryi9JxbMCFM/w-d-xo.html
      Hope this helps

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

      @@Boxply Thank you❤

  • @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  9 หลายเดือนก่อน

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

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

    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

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

      3D

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

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

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

    yo how do i change the keybind?

  • @обрубок-г3ц
    @обрубок-г3ц ปีที่แล้ว

    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.

    • @обрубок-г3ц
      @обрубок-г3ц ปีที่แล้ว +1

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

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

    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!

  • @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!

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

    GOOD TUTORIAL BOIII

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

    Awesome!!

  • @dontCallMe..
    @dontCallMe.. ปีที่แล้ว

    How can i make it work with prefabs

    • @dontCallMe..
      @dontCallMe.. 11 หลายเดือนก่อน

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

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

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

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

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

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

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

  • @alkungfu
    @alkungfu 11 หลายเดือนก่อน +2

    It isnt working at all

    • @Boxply
      @Boxply  6 หลายเดือนก่อน +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

  • @dontCallMe..
    @dontCallMe.. 11 หลายเดือนก่อน

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

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

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

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

    How to make pickup drop system for my mobile game

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

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

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

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

  • @ordinarynerdofficial
    @ordinarynerdofficial 11 หลายเดือนก่อน

    It doesn't work with my ragdoll character

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

      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

  • @Sproute-RL
    @Sproute-RL 7 หลายเดือนก่อน

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

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

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

    • @Sproute-RL
      @Sproute-RL 6 หลายเดือนก่อน

      @@Boxply ya

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

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

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

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

    • @Sproute-RL
      @Sproute-RL 6 หลายเดือนก่อน

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

  • @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 7 หลายเดือนก่อน

      yea@@Boxply

  • @AlexDiaz-t7e
    @AlexDiaz-t7e 9 หลายเดือนก่อน

    doesnt work with ragdolls

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

      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

  • @homeholer
    @homeholer 23 วันที่ผ่านมา

    idk why but it just doesn't work lol

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

    its great but outdated now so its pretty scuffed

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

      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 6 หลายเดือนก่อน

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

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

    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.

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

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

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

      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

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

      @@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

  • @raelroque5595
    @raelroque5595 28 วันที่ผ่านมา

    stop waste my time bro

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

    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 11 หลายเดือนก่อน

      the camera needs the MainCamera tag to it

    • @Cat_6921
      @Cat_6921 11 หลายเดือนก่อน

      it is@@HackingStuffIDontKnow

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

      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

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

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

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

      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

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

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