We got a lot of questions about the physics stability of our linked chains so I’m passing the “mike” to our programmer so he can explain how we made it work.
Few clues about (almost) physically correct chain (in this case in VR but nothing is standing in a way of using this in other games).
First I must write something about interactions with objects in VR. In SteamVR SDK (which we used from the beginning) picking up something is just changing the object’s parent to hand (controller). This is equal to changing object position via transform.position. It is efficient but really bad for immersion. Imagine that it’s like teleporting objects from one position to another – even with a high rate of frames, it makes strange complications with collisions and constraints with other objects.
We had to change it. The best solution that I found was in Newton VR scripts – I will call it “magnetic picking”. It changes Rigidbody.velocity to target velocity multiplied by a constant value, called by Newton VR developer, a “velocity magic”. This creates force added to a picked object that makes an object follow the hand. Same thing u need to do with rotation using few calculations with quaternions and movetoward angularVelocity. U need to do it every frame for a picked object.
Now when your object is pickable we can create a chain with joints. To do that we created a procedural script to put every chain link incorrect position, in our case, this is a circular shape. We use two prefabs that we instantiate interchangeably.
Every chain link after instantiating must be connected by HingeJoint with previous (and last one with first). Remember about the correct axis for hinge joints. Chainlinks’ prefabs can hold HingeJoint components with correct settings. You must figure out the best settings for your chain to minimalize the chance for a jitter explosion.
There is always a probability for jitter crash in some specific cases. For that, we made a respawn trigger script after the “explosion” chain will just respawn in the original position. But with correct settings that are a really rare case.
“Magnetic picking” of chains works fine with two controllers (what in our case is necessary to put them on our cogs). With one controller you can pick it up but rotation will never be correct, that’s because we are adding force for one chain link and others connected to it with hingejoints are dragging it down.
There is a way to use that chain like V-belt with friction to propel something, but we got cogs working on physics collision, so we made chain links with proper collider capsules and now it is (almost) physical correct.
One more thing is we can’t make prefab from the created chain. Unity has a strange problem properly saving spring values in prefab and that results in strange behaviors. So on every scene with chain, we generate them procedurally.