soft_body.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. :article_outdated: True
  2. .. _doc_soft_body:
  3. Using SoftBody
  4. ==============
  5. Soft bodies (or *soft-body dynamics*) simulate movement, changing shape and other physical properties of deformable objects.
  6. This can for example be used to simulate cloth or to create more realistic characters.
  7. Basic set-up
  8. ~~~~~~~~~~~~
  9. A :ref:`SoftBody3D <class_SoftBody3D>` node is used for soft body simulations.
  10. We will create a bouncy cube to demonstrate the setup of a soft body.
  11. Create a new scene with a ``Node3D`` node as root. Then, create a ``Softbody`` node. Add a ``CubeMesh`` in the ``mesh`` property of the node in the inspector and increase the subdivision of the mesh for simulation.
  12. .. image:: img/softbody_cube.png
  13. Set the parameters to obtain the type of soft body you aim for. Try to keep the ``Simulation Precision`` above 5, otherwise, the soft body may collapse.
  14. .. image:: img/softbody_cube_menu.png
  15. .. note:: Handle some parameters with care, as some value can lead to strange results. For example, if the shape is not completely closed and you set pressure to more than 0, the softbody will fly around like a plastic bag under strong wind.
  16. Play the scene to view the simulation.
  17. .. tip:: To improve the simulation's result, increase the ``Simulation Precision``, this will give significant improvement at the cost of performance.
  18. Cloak simulation
  19. ~~~~~~~~~~~~~~~~
  20. Let's make a cloak in the Platformer3D demo.
  21. .. note:: You can download the Platformer3D demo on `GitHub <https://github.com/godotengine/godot-demo-projects/tree/master/3d/platformer>`_ or `the Asset Library <https://godotengine.org/asset-library/asset/125>`_.
  22. Open the ``Player`` scene, add a ``SoftBody`` node and assign a ``PlaneMesh`` to it.
  23. Open the ``PlaneMesh`` properties and set the size(x: 0.5 y: 1) then set ``Subdivide Width`` and ``Subdivide Depth`` to 5. Adjust the ``SoftBody``'s position. You should end up with something like this:
  24. .. image:: img/softbody_cloak_subdivide.png
  25. .. tip:: Subdivision generates a more tessellated mesh for better simulations.
  26. Add a :ref:`BoneAttachment3D <class_BoneAttachment3D>` node under the skeleton node and select the Neck bone to attach the cloak to the character skeleton.
  27. .. note:: ``BoneAttachment3D`` node is to attach objects to a bone of a armature. The attached object will follow the bone's movement, weapon of a character can be attached this way.
  28. .. image:: img/softbody_cloak_bone_attach.png
  29. To create pinned joints, select the upper vertices in the ``SoftBody`` node:
  30. .. image:: img/softbody_cloak_pinned.png
  31. The pinned joints can be found in ``SoftBody``'s ``Attachments`` property, choose the ``BoneAttachment`` as the ``SpatialAttachment`` for each pinned joints, the pinned joints are now attached to the neck.
  32. .. image:: img/softbody_cloak_pinned_attach.png
  33. Last step is to avoid clipping by adding the Kinematic Body `Player` to ``Parent Collision Ignore`` of the ``SoftBody``.
  34. .. image:: img/softbody_cloak_ignore.png
  35. Play the scene and the cloak should simulate correctly.
  36. .. image:: img/softbody_cloak_finish.png
  37. This covers the basic settings of softbody, experiment with the parameters to achieve the effect you are aiming for when making your game.