Rope Swing , Hinge Problem
Hi i am using a hinge joint to make a swinging effect however the hinge doesn't do what i want to, is there another way to make a swinging effect where the object can get closer to the tethered point, because with the hinge it feels like solid but i want it to be like a rope or something but very simple between 2 points only. the hinge doesnt allow the object to come closer to the center only rotates
Robe or Rope? For Robe, you can use the cloth effect in Unity. For Ropes, you might be able to use this to achieve what you're after.
Oh sorry :D , I meant rope. I don't want a whole rope system I will draw the rope with a simple line renderer between two points butr how can I make the physics something like a hinge
Yea but it should allow the object to be able to move closer to the tether point but not away
Lockstep's explanations below are very good to achieve what you're after. But it seems that none of his answers fit into your bill. Could you show a Youtube or an animation of what you're trying to achieve?
Answer by Lockstep · Jan 24, 2014 at 12:16 AM
A realistic rope could be realized by a chain of configurable joints.
Create an empty gameObject and name it "rope". Create a couple of children for your rope named "part1-x" and one named "base". Position them in a straight line with fixed distances. The base is the fix point in the middle.
Give every part a rigidbody and a configurable joint (hinge joints only rotate around one axis like a door. use those if you want to make a 2D game). The base gets a kinematic rigidbody.
Now set up the connected body for each joint. Part1 gets the base, part2 gets part1 etc. Make sure the anchor matches with the position of the connected body.
To render the robe, the easiest thing would be a line renderer.
I don't want to do all that I only need 2 points I am sure there is away to do it without the hinge joint
Now I'm not sure of what you are trying to do. The solution for the rope provides you with this:
The ball can't go further away from the center than the length of the chain but he can move closer to it. Are you by any chance looking for something that can slide along a pole? Or do you simply want to restrict the movement range to a certain area?
i simply want to restrict the movement range to a certain area, but with physics can i do that with a rigidbody ?
You can do that pretty easily. Deter$$anonymous$$ing the distance between two points in a sphere is easy - it's just the magnitude of the difference between the coordinates. So, you can test whether the object is inside or outside your defined range, or "rope length" with a simple test. Then, you can deter$$anonymous$$e the direction from the object to the centre point by subtracting the object position from the centre position - that's another simple calculation. Then, you just need to use AddForce in that direction, and you've got yourself a boundary.
Of course, the simpler way is to just do what Lockstep already said, and use an inverted sphere mesh as a collider, with a layer mask if you want other objects to ignore it.
Answer by belamessex · Mar 30, 2016 at 04:59 AM
I would try a spring joint. Does pretty much exactly what you are asking for. You should be able to test it by modifying your script's HingeJoint reference with SpringJoint and add a spring joint to your object in the inspector.