Create the visual spring in Unity?

There's the SpringJoint, but what if you want a vivid spring that expands and compresses (in 3 degrees of freedom) connecting the two objects?

Should I:

A: 1) import 3d spring mesh. 2) fudge some procedural compress parameters

B: procedurally generate the spring mesh completely

C: a better way?

I know this is an old question, but in case anyone has a similar query, this is what I would do:

  • Create a spring shaped model with morphs in your 3D modeler which stretch and compress the spring to its maximums
  • Use Mega-fiers to import the morphs into Unity
  • Buy and use Mega-fiers from the Asset store and use its morphing capabilities
  • Drive the morphing of the spring to null points (empty game objects) driven by a Unity SprintJoint
  • You can also use Mega-fiers to deform the spring bending while it is morphing

That way Unity's physics create the motion (which looks good from my tests) and the spring model will look good because you are just animating the morph via physics.

By the way, I've found the trick to getting SpringJoints to look right is to put visible Gizmos on the NullPoints that are the anchor and weight of the SpringJoint and make Gizmos visible during runtime while you play with the numbers to figure out the correct range to set the Spring force, mass and dampers...

I'm not an artist but as programmer i don't recommend creating a spring procedurally(It would be a nasty piece of work and don't look great i think ;) ).

It would be easier to create the spring in max/maya/whatever and attach two bones to your spring. One at each end and then skin the vertices to both bones (the weights lineary adjusted). Imported into Unity you get a SkinnedMeshRenderer and your two bones as seperate GameObjects. Now you can joint them together as you like and if it's skinned right it should bend and strech the right way.

I should append that i never used spring joints before, but basically that's how it should work.

Good luck

Hi ina,

I'm not sure how good you are wanting it to look but one simple solution could be adjusting the Y scale via sine wave.

You might have to tinker with this code a bit. I don't have time to go test it atm.

    var speed = 5;
    var amplitude = 2;
    transform.localScale.y += amplitude * Mathf.Sin(Time.time * speed);

This will scale your object up and down replicating a spring. c(=