组装载具
To create the main character — a car, we need its 3D model. You can use your own model: a simplified physical model of the car requires the body and 4 wheels to be implemented as separate objects.为了创建主角,一辆汽车,我们需要它的 3D 模型。你可以使用自己的模型:简化的物理模型要求车身和四个轮子作为独立对象存在。
To simplify customization, we recommend using a correctly prepared and imported model, all objects of which are unscaled and have their forward axes oriented towards the Y+ axis.为了简化自定义过程,我们推荐使用一个正确准备并导入的模型,所有对象未缩放,且其前向轴朝向Y+方向。
Let's use the pickup model from the race/props/pickup folder. In the context menu of the pickup.node asset, select Place as Node Content and click in the Editor viewport to add the model with the preset materials.我们将使用race/props/pickup文件夹中的皮卡模型。在pickup.node资源的上下文菜单中选择Place as Node Content,然后在编辑器视口中点击添加带预设材质的模型。
Customizing the car physical model自定义汽车物理模型#
The hierarchy of the car nodes in the scene is as follows:场景中汽车节点的层级结构如下所示:
The car body (pickup_frame), wheels (the wheels group), and a decorative car freshener (car_freshner) will be physically active, all other nodes are the car body children that follow its movements.车身(pickup_frame)、轮子(wheels组)和一个装饰用的挂件(car_freshner)将具有物理行为,其它所有节点是车身的子节点,并随车身移动。
- In the pickup_frame node parameters, the Physics tab, select the Rigid physical body. Keep the default values in all its settings.在pickup_frame节点参数的Physics标签页中,选择Rigid物理体。保留所有设置的默认值。
-
Let's also add a collision shape in the Shapes section and use the simplest and most stable shape: Box shape. Select the Box option from the list and click Add. Click Edit Size to customize the collision shape dimensions and roughly replicate the body shape: the simpler the physical representation, the better it is for calculations.接下来在Shapes部分添加一个碰撞形状,并使用最简单、最稳定的形状:Box shape。从列表中选择Box选项,然后点击Add。点击Edit Size按钮来自定义碰撞盒的大小,尽量与车身形状大致吻合:物理形状越简单,计算性能越高。
-
Let's set the following collision shape parameters:设置以下碰撞体参数:
- Friction coefficient: 1.0Friction(摩擦系数):1.0
- Restitution coefficient: 0.0Restitution(弹性系数):0.0
- Car body Mass: 60 kg车身Mass(质量):60 公斤
注意The real car body weight is about 2000 kilograms, but for a physical game engine the real mass is not always the best option. The model must simulate the real object's behavior while remaining optimal for real-time computations. Therefore, configuring the physical model is all about selecting coefficients to ensure that the model behaves as naturally as possible.真实汽车车身的重量大约为 2000 公斤,但在物理游戏引擎中,真实质量并不总是最佳选择。模型应在尽可能自然地模拟真实行为的同时,保持对实时计算的优化。因此,配置物理模型的关键是选择合适的参数,使其行为尽可能接近真实。 -
Disable the Shape Based option to override some parameters manually:关闭Shape Based选项,以便手动设置部分参数:
- CMass (center of mass relative to the model pivot point) — move it towards the hood, since most of the mass is on the mechanisms.CMass(相对于模型轴心的质心):将其稍微移向车头,因为大多数质量集中在引擎部位。
- ADamping (rotation movements damping coefficient) — increase it a bit to make the car body more stable.ADamping(旋转运动阻尼系数):略微提高该值以增强车身稳定性。
- Assign the Rigid physical body to all four wheels.为四个轮子都分配Rigid物理体。
Configuring Joints配置关节#
To link the wheels with the body, we need to configure joints connecting them.为了将轮子与车身连接起来,我们需要配置关节将它们相连。
-
Select the car body pickup_frame node and add four Wheel joints in the Joints section selecting the wheels one by one.选择车身节点pickup_frame,然后在Joints部分中依次为每个轮子添加四个Wheel关节。
- Select joints one by one and click the Fix 0 button for each of them, to move the joint connection point to the center of each wheel. Now each wheel is connected to the car body and will continuously tend to the specified center.逐个选择关节,并点击每个关节的Fix 0按钮,将连接点移动到各个轮子的中心位置。现在每个轮子都已与车身连接,并将持续向指定中心位置靠拢。
-
Select all joints using the Shift button and set the following parameter values:按住Shift键选择所有关节,并设置以下参数值:
- Iterations (number of calculation iterations per joint): 2Iterations(每个关节的计算迭代次数):2
- Linear/Angular Restitution coefficients: 0.2Linear/Angular Restitution(线性/角度恢复系数):0.2
- Linear Damping coefficient: 300Linear Damping(线性阻尼系数):300
- Linear From and Linear To (shock absorber operating range): 0.1 meter. You can increase these values to make suspension more active, but the whole system may become unstable on uneven surfaces and at high speeds.Linear From 和 Linear To(减震器工作范围):0.1 米。你可以增加这些值来使悬挂更具动态效果,但在不平坦地形和高速行驶时整个系统可能会变得不稳定。
- Linear Spring (shock absorber force): 500Linear Spring(减震器弹力):500
- Tangent/Binormal Friction (longitudinal and transverse friction coefficients for tires): 4.0 and 1.0. You can try different values and adjust the grip between the tires and the ground.Tangent/Binormal Friction(轮胎纵向与横向摩擦系数):4.0 和 1.0。你可以尝试不同的值以调整轮胎与地面的抓地力。
- Wheel Mass: 10 kgWheel Mass:10 千克
- Wheel Radius: 0.37 m for the provided model. If you use your own 3D model, set the wheel radius value corresponding to your model wheels.Wheel Radius:对于提供的模型为 0.37 米。如果你使用自己的 3D 模型,请根据你的模型轮子设置半径。
-
Each Wheel joint represents a virtual wheel and uses so-called Physics Intersections to preform a simplified detection of collisions with the ground surface.每个Wheel关节代表一个虚拟轮子,并使用所谓的Physics Intersections(物理交集)来执行简化的地面碰撞检测。
Select the ground_plane node and enable the Physics Intersection option. This will make the geometry "visible" to the joints that simulate the wheels. And enabling the Collision option makes the geometry available for traditional collisions with collision shapes, such as the car body.选择ground_plane节点,并启用Physics Intersection选项。这将使几何体对模拟轮子的关节“可见”。启用Collision选项则可使几何体参与常规碰撞(如与车身碰撞形状的交互)。
-
Save the changes (Ctrl+S) and enable physics simulation in the Editor to verify that the physics model is correct. Now the car should gain weight and stand on wheels, and the shifted center of mass and rather heavy wheels will make it more resistant to rollover.保存更改(Ctrl+S),并在编辑器中启用物理模拟以验证物理模型是否正确。现在汽车应该具有重量并立于车轮之上,偏移的质心和较重的轮子将提高抗侧翻能力。
Now disable the physics simulation to continue fine-tuning.现在请禁用物理模拟,以继续进行后续调试。
Fine-Tuning Air Freshener (optional)精细调整空气清新器(可选)#
Adding dynamic details like this can add to the car driving experience.添加这类动态细节可以增强驾驶体验。
- Select the car_freshner node and assign the Rigid body to it in the Physics tab.选择car_freshner节点,并在Physics标签中为其分配Rigid物理体。
- Add the Box collision shape.添加Box碰撞形状。
- Select the pickup_frame node and add the Ball joint in the Joints section. Press the Fix 0 button in its settings to shift the joint center to the current position of the freshener node.选择pickup_frame节点,在Joints部分添加Ball关节。在其设置中点击Fix 0按钮,将关节中心对齐到当前清新器节点的位置。
-
Configure its parameters as follows:设置以下参数:
- Damping coefficient: 1.0Damping(阻尼系数):1.0
- Physical bodies connected with a joint won't collide if the Collision option is disabled, let's keep it as it is.如果禁用Collision选项,被连接的物理体之间不会发生碰撞,我们就保留该设置。
- Angle (maximum possible swing angle from the initial position): 155Angle(相对于初始位置的最大摆动角度):155
Now the air freshener will move actively depending on the loads experienced by the vehicle. 现在,空气清新器将根据车辆受到的载荷产生动态摆动。
本页面上的信息适用于 UNIGINE 2.20 SDK.