- Home /
Connect rigidbody to another moving rigidbody to simulate a hanging weight
I have a rigidbody which moves along a spline at a constant speed. (See image attached.) It's set to kinematic.
Here is (a simplified version of) the code which moves it along the spline. I've removed all the spline-related particulars since I'm only interested in the rigidbody stuff.
private void FixedUpdate()
{
m_progress += (m_ speed * Time.fixedDeltaTime) % 1f;
SetPosition(m_spline.GetPoint(m_progress));
if (m_faceForward)
SetRotation(m_spline.GetDirection(m_progress));
}
private void SetPosition(Vector3 position)
{
m_rigidbody.MovePosition(position);
}
private void SetRotation(Vector3 forward)
{
m_rigidbody.MoveRotation(Quaternion.LookRotation(forward, Vector3.up));
}
This works nicely when it's only the spline following cube.
I want to be able to attach another weighted rigidbody so that it is 'pulled' by the spline following rigidbody. The idea is to have a factory where objects are being transported by a system of overhead rails. Think of the doors in Monsters Inc.
However simply using a hinge or sprint joint doesn't seem to do the trick. The hanging objects swing wildly, moving crazily and sometimes doing entire 360s around the spline rigidbody.
I guess I need some setup for a configurable joint. I want the weighted rigidbody to generally hang downwards but also twist a little bit, having the impression of being very heavy. Also if there are multiple suspended weights they might occasionally bang against one another. It should also be impossible to for the object to rotate above a certain point. (i.e. "going over" the spline rigidbody)