2
$\begingroup$

I want to model and animate a spring in blender. But my animation seems not to be compatible with unity.

What I tried so far:

Curve

  1. Created a curve and added volume to it
  2. Added a Bone
  3. Mapped the bone to the curve with Hooks
  4. Animated via key frames

The Problem with this is, that it works perfectly in blender, but unity just ignores the animation. You can see the bone, but the spring stays still.

Curve to mesh

  1. Created a curve and added volume to it
  2. Converted to mesh
  3. Added a Bone with parenting
  4. Animated via keyframes

The problem with this is that it distorts the thickness of the spring instead of just lowering the space between the rings. But the animation does import correctly to unity.

spring animation in blender

(Curve left, Curve to mesh right)

Is there any way to animate a spring like shape without distorting the mesh too much, which is compatible with the latest version of unity?

$\endgroup$

1 Answer 1

4
$\begingroup$

Use a Shape Key instead of an Armature to animate the spring. Shape Keys are exported to Unity via FBX, and are called Blend Shapes.

For Blender 3.4 and and above replace the Z-Up Curve Tilt node with a Set Curve Normal node with Mode set to Z Up

You can use Geometry Nodes to create the spring in Blender. Here is a Node Setup:
Blender Geometry Nodes Spring Generator

The Z-Up Curve Tilt is a group (no longer needed in Blender 3.4 and above):
Z-Up Curve Tilt Node Group2
I got it here from blenderartist Zeroskill

The input parameters of the modifiers will look like this:
enter image description here

You can adjust these until you are happy with your spring, then test the Spiral Height value for what you would like your spring to look like in the compressed state and set this value in the Spiral Compressed Height. The Spiral Height and Spiral Compressed Height should be different, and you wont see the effect of the Spiral Compressed Height until later.

Now apply the modifier. Then, in the Object Data Properties look for Attributes. You should find an Attribute called "compressed_pos". This has been generated by the Geometry Nodes setup.
attribute

You will need to convert this Attribute to a Shape Key. You can do that by selecting it and then running this script:
script to convert an attribute to a shape key

You should then get a Basis and a compressed_pos Shape key.
shape key

The Model can now be exported as FBX and animated with Blend Shapes in Unity

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .