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
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
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?
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
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?
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
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)
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 ? :)
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
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)
@@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?
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
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
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
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.
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
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?
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
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)
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.
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
@@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
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
If you have any issues whatsoever (or just want to leave a commendation), feel free to let me know here in the comment section.
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
Thanks! And if that works better than go all for it! Good luck on your game
Can you make an updated version for unity 5?
i want to make it when E is pressed...
How would i make it so when you press a button, say F, it freezes in the air?
Uh... the cube just dissapears when i play, but is still there in the editor
i have a strange bug where when i hit play, the camera is separated from my player, causing it to move weird.
It isnt working at all
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
Brilliant. Grabbing Works like a Charm
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?
use world space - change
where to add camera plane code?
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
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?
CAN SOMEONE PLEASE HELP ME!!!!!!!! It keeps saying jointdrivemode is no longer supported. and its on 2022 editor⚠⚠⚠
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?
Just get Dani's movement script. He has a video on his channel
help! it says that joint drive mode mode is obsolete on the Rigidbody script line 90
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
GOOD TUTORIAL BOIII
Whose code doesn't work? I rewrote it. write to me and I’ll tell you what to fix
also, the line isnt tocuhing at all the object im holding, how can i fix this?
nvm i used probulder to make cubes and that was the problem
Well, glad it's fixed!
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)
You probably didn't set the tags and etc right.
i want to make it when E is pressed...
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 ? :)
Probably input system. It should work fine with newer versions
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!
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
I need help, the object are just gliding after I touch them, how do i stop it?
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)
@@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?
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
@@Boxply Thank you❤
Awesome!!
is there anyway I can trigger it with right click?
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
@@Boxply its not letting me change from onmousedrag system to a normal input system, the trail line is not following the object im dragging
Ohh.
On MouseDrag only works for left click.
You might have to set up a custom function replicating onmousedrag but for the left key
@@Boxply ty!! ill try!
Gl!
The line looks weird when u move (fast ?), Did u put that line rendering thing to LateUpdate ?
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
@@Boxply at 4:46 i guess
It doesn't work with my ragdoll character
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
How to make pickup drop system for my mobile game
Is it 3d? If it's 3d just replace the mouse down functions for input from touch
@@Boxply I am beginner can you please make a tutorial video please
the "JointDriveMode" is no longer supported in DragRigidbody script
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.
@@Raumfist thanks man, but I gave up on unity in general :)
first: when i drag it goesa always to the corner of the object
second: i can fly
What's your scene looking like right now? Do you have the tags and stuff set properly?
@@Boxply ya
And. What do you mean by "it always goes to the corner of the object?" The line renderer?
I think the flight part may have to do with your movement controller?
@@Boxply b ecause u use the gameobject posotion the position is automatiocally at the corner of the object
doesnt work with ragdolls
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
What's the "Camera Plane" for?
It's a pretty detailed thing but in this circumstance, simply put, it turns the camera view relative to plane
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?
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
@@Boxply Okay, I'll try that. Thanks!
How can i make it work with prefabs
you cant dump ass ur working with online and not prefabs lol
Basically you attach the script to the prefab and give it the specific values and tags. It should work just find
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
3D
Hey loved the video I was just hoping you could link the music you used during the tutorial to my comment
All the music I used is by Context Sensitive on UA-cam. Look him up! Thanks for taking an interest
Hey are u from india ?
Well, No I'm not from India. Though, is my accent like that? Haha
yea@@Boxply
its great but outdated now so its pretty scuffed
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
@@Boxply good for you! that'll be great i subscribed
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)
the camera needs the MainCamera tag to it
it is@@HackingStuffIDontKnow
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
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.
Also there is no range. the error runs even when i click from far away
I resolved the stretching problem, but not the other problems
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
@@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
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