I’m trying to simulate a shower spiral cable like in the picture blow. [188357-sh1.png*_|188357]. I tried all the Joints for the movement and rotation of the bones but couldn’t do what I wanted. Finally, I wrote a script for the transforms of the bones, but here, too, I couldn’t manage to calculate the rotations of the bones depending on their movements.
using UnityEngine;
public class SetTransforms : MonoBehaviour
{
[SerializeField] float force = .033f;
GameObject[] bones;
Vector3 diffPos, pos1, pos2;
Vector3 diffRot, rot1, rot2;
int numBones;
// Start is called before the first frame update
void Start()
{
numBones = transform.childCount;
bones = new GameObject[numBones];
for (int i=0; i<numBones; i++)
{
bones *= transform.GetChild(i).gameObject;*
}
diffPos = new Vector3(0, 0, 0);
pos1 = pos2 = bones[0].transform.position;
}
// Update is called once per frame
void Update()
{
pos1 = bones[0].transform.position;
rot1 = bones[0].transform.eulerAngles;
diffPos = pos1 - pos2;
diffRot = (rot1 - rot2);// * Mathf.PI / 180;
diffPos = diffPos + diffRot;
if (pos1 != pos2) SetPos();
pos2 = pos1;
rot2 = rot1;
}
void SetPos()
{
for (int i=1; i<numBones; i++)
{
Vector3 pos = bones.transform.position + diffPos * force * ((float)numBones - (float)i);
//Vector3 rot = bones.transform.eulerAngles + diffRot * force * ((float)numBones - (float)i);
//bones*.transform.position = _pos;*
bones*.transform.position = pos;*
}
}
}_
I would be grateful if you help.
*
*