Shower spiral cable simulation
I'm trying to simulate a shower spiral cable like in the picture blow. I designed the cable in Blender with Invers Kinematics
. 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[i] = 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[i].transform.position + diffPos * force * ((float)numBones - (float)i);
//Vector3 _rot = bones[i].transform.eulerAngles + diffRot * force * ((float)numBones - (float)i);
//bones[i].transform.position = _pos;
bones[i].transform.position = _pos;
}
}
}
I would be grateful if you help.
Answer by abadanoglu · Nov 07, 2021 at 09:12 PM
Here is for those who are interested, the link of the package file
Your answer
![](https://koobas.hobune.stream/wayback/20220613045034im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Wrong normals when object is rotated and using custom world aligned shader? 4 Answers
Check rotation of an obstacle 0 Answers
Making an object spin on impact 0 Answers
Rotation problem: Object rotates but shouldn't 0 Answers
Rotation of game objects 0 Answers