Work in progress

The content of this page was not yet updated for Godot 4.2 and may be outdated. If you know how to improve this page or you can confirm that it's up to date, feel free to open a pull request.

使用 SoftBody

柔体(或柔体动力学)模拟可变形物体的运动,改变形状和其他物理特性。例如,这可以用于模拟布料或创建更逼真的角色。

基本设置

A SoftBody3D node is used for soft body simulations.

我们将创建一个弹性立方体来演示柔体的设置。

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.

../../_images/softbody_cube.png

设置参数以获得你想要的柔体类型。尽量保持 Simulation Precision(模拟精度)的数值高于 5,否则该柔体结构可能会瓦解。

../../_images/softbody_cube_menu.png

备注

小心处理一些参数,因为改动某些数值会导致奇怪的结果。例如,如果形状未完全封闭并且你将压力设置为大于 0,则柔体将如同在强风下的塑料袋一样飞舞。

播放该场景以查看模拟结果。

小技巧

要改善模拟结果,可以增大 Simulation Precision,但同时会大幅度增加性能成本。

斗篷模拟

我们将在 Platformer3D 演示中制作一个斗篷。

备注

你可以在 GitHub资产库上下载 Platformer3D 演示。

打开 Player 场景,添加一个 SoftBody 节点并为其指定一个 PlaneMesh

打开 PlaneMesh 属性并设置大小(x:0.5 y:1),然后将 Subdivide Width(宽度细分)和 Subdivide Depth(深度细分)设置为 5。调整 SoftBody 的位置。你应该看到如下所示:

../../_images/softbody_cloak_subdivide.png

小技巧

细分会生成更细密的网格,以便更好地进行模拟。

Add a BoneAttachment3D node under the skeleton node and select the Neck bone to attach the cloak to the character skeleton.

备注

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.

../../_images/softbody_cloak_bone_attach.png

要创建固定的关节,选择 SoftBody 节点上方的顶点:

../../_images/softbody_cloak_pinned.png

SoftBodyAttachments 属性中可以找到图钉关节,为每个被图钉关节选择 BoneAttachment 作为 SpatialAttachment,被图钉关节连接到颈部。

../../_images/softbody_cloak_pinned_attach.png

最后一步,通过在 SoftBodyParent Collision Ignore 中添加动力学物体 Player 来避免裁切。

../../_images/softbody_cloak_ignore.png

播放场景,应该已经正确模拟了斗篷。

../../_images/softbody_cloak_finish.png

这涵盖了柔体的基本设置,当你制作游戏时,尝试这些参数来达到你想要的效果。