Hello, so I have GameObjects which look something like this. (consisting of primitive spheres and cylinders)
I want the cylinders, which connect the spheres, to change in Y-Scale over time. in order to make it look like the cylinders is some kind of pistons (so the cylinders should continuously grow and then shrink again). The top and bottom side of the cylinders should never be visible and always hidden inside the sphere. So the spheres should move attached to the ends of the cylinder.
I tried to achieve this by writing a simple script that changes the Y-scale over time and connecting the spheres to the cylinders with joints, but the result wasn’t satisfying at all. (I tried FixedJoints, CharacterJoints, SpringJoints and HingeJoints, but none worked). Currently in this attempt, I am using FixedJoints, each sphere has a Rigidbody (Use Gravity and Is Kinematic both set to false) and a SphereCollider, and each Cylinder has also a Rigidbody with Use Gravity set to true, and Is Kinematic set to false, but no Collider.
I don’t know a lot about joints, I looked at the manual and watched two videos (including the one from Unity itself), but am not really smarter than before. The SpringJoint has Connected Anchor values. One way to solve my problem would probably be to calculate that Anchor every frame anew (would it?), but that seemed like a lot of effort for such a task. Isn’t there a more convenient way?
I also thought about hiding a second cylinder with the same dimension as the first one, inside the first one, and only change the position of this second cylinder, but that also seemed like a weird solution. Furthermore, the cylinder might be more than twice as long in its extended state than when contracted.
Thank you for reading my question!
EDIT: I made an animation how I want the result to look, to make it more clear. (Except for the buggy string things on the top right corner of the thing, didn’t know how to remove that, sorry)