Quick Start 快速开始
Vehicle Model Requirements
Ensure that your vehicle model has the appropriate Unity rotation and pivot points. The model should use the following axes: Z - Forward, Y - Up, and X - Right. If your model has incorrect rotation and/or pivot points, consult this guide.
Maintain a vehicle scale of [1,1,1]. Adjust the vehicle scale using the model import settings in Unity or 3D software prior to vehicle setup.
Physics Settings
- For PC games, it is recommended to change the from the default 0.02 (50Hz) to 0.01667 (60Hz), 0.01 (100Hz), or even 0.00833 (120Hz) for smoother physics behavior. For mobile devices, set this value between 0.02 and a maximum of 0.03 (33Hz), but note that this may result in lower physics quality.
Fixed Timestep
- All NWH assets use only SI units (kg, m, N, etc.).
If making an open-world game with a large-scale map (> ~4000 units), the shifting origin is required (not only for this asset, but in general with game engines that use floating point precision). Explanation.
Automatic Setup
Vehicle Setup Wizard 车辆设置向导
To set up a vehicle automatically, use the VehicleSetupWizard.
Ensure that your vehicle has correct pivots and rotation first. Then, attach the to the root object of the vehicle—where the Rigidbody would typically be placed. Follow the steps from the wizard inspector.
The logs all actions, errors, and warnings in the console. Review and correct these manually if necessary.
Depending on the settings, you might need to set up the input manually: Input Setup pageVehicleSetupWizard
VehicleSetupWizard
要自动设置车辆,请使用 VehicleSetupWizard。 首先确保您的车辆具有正确的枢轴和旋转。 然后,将 附加到车辆的根对象,即通常放置刚体的位置。按照向导检查器中的步骤进行作。这会在控制台中记录所有作、错误和警告。如有必要,请手动查看并更正这些问题。根据设置,您可能需要手动设置输入: Input Setup 页面 VehicleSetupWizard
VehicleSetupWizard
Manual Setup 手动设置
Rigidbody 刚体
Add a component to the vehicle root, Car in the image above. Set the mass to a reasonable value, e.g., 1400.
Rigidbody
将组件添加到车辆根,即上图中的 Car。将质量设置为合理的值,例如 1400。 刚体
Colliders 碰撞体
Add a (, , etc.) to the vehicle. Rigidbody requires a collider to function properly.
Collider
BoxCollider
MeshCollider
将 (、 等) 添加到车辆。刚体需要碰撞器才能正常运行。 碰撞器(Collider)
箱体(Collider Box)碰撞器(Collider
MeshCollider)
Variable Center of Mass
可变质心
Add the VariableCenterOfMass component to the vehicle root. This is not required but is recommended, as it allows for the adjustment of the Center of Mass and Inertia, both of which significantly impact handling.
For Unity 2023 and newer, you can adjust the center of mass and inertia tensor directly on the Rigidbody, so this script will not be needed.
将 VariableCenterOfMass 组件添加到车辆根。这不是必需的,但建议这样做,因为它允许调整 Center of Mass 和 Inertia,这两者都会显着影响控性。对于 Unity 2023 及更高版本,您可以直接在刚体上调整质心和惯性张量,因此不需要此脚本。
WheelController3D WheelController3D 控制器
For a vehicle to function properly, it requires wheels. NWH Vehicle Physics uses the included asset WheelController3D instead of the default WheelCollider. For more information, consult the WheelController Setup page. Since v10.0, WheelCollider can also be used.
车辆要正常运行,需要轮子。NWH Vehicle Physics 使用包含的资源 WheelController3D,而不是默认的 WheelCollider。有关更多信息,请参阅 WheelController 设置页面。从 v10.0 开始,也可以使用 WheelCollider。
- Attach the to a separate object from the wheel. This object will serve as a suspension anchor and represent the beginning of spring travel. Position it above the wheel center. The easiest way to create these objects is to duplicate the existing wheel objects, remove all components except the , and move the duplicated objects slightly above the wheel center.
WheelController
Transform
将 附加到与轮子不同的对象。这个对象将用作悬浮锚,代表春天旅行的开始。将其放置在车轮中心的上方。创建这些对象的最简单方法是复制现有的轮子对象,删除除 之外的所有组件,然后将复制的对象移动到轮子中心的略上方。WheelController
变换
- Add the component to the objects created in the previous step. The will initialize itself with default values and attempt to set the necessary fields automatically. Ensure the following fields are set:
WheelController
WheelController
将组件添加到在上一步中创建的对象。将使用默认值初始化自身,并尝试自动设置必要的字段。确保设置以下字段:WheelController
WheelController
Parent
- root object of the vehicle. Must have a attached. Car for this example.Rigidbody
Parent
- 车辆的根对象。必须有一个附件。Car 的实例。刚体
Visual
- wheel model. Wheel_FL, Wheel_FR, etc. for this example.视觉
- 车轮模型。Wheel_FL、Wheel_FR 等。
- Turn on Gizmos and select the wheels. The wheel gizmo and suspension gizmo will appear. Adjust the and of the until they fit the wheel model.
Width
Radius
WheelController
启用 Gizmo 并选择轮子。将出现车轮 Gizmo 和悬架 Gizmo。调整 和 直到它们适合车轮模型。Width
Radius WheelController
(宽度半径WheelController)
- Press play. The vehicle suspension is now functional. If the vehicle jitters, jumps, or exhibits other issues, check that the vehicle has a set up with the correct mass and at least one . For more information, consult the Troubleshooting section of the WheelController Setup page.
Rigidbody
Collider
按下播放键。车辆悬架现在可以正常工作。如果无人机抖动、跳跃或出现其他问题,请检查无人机是否具有正确的质量设置和至少一个 。有关更多信息,请参阅 WheelController 设置页面的故障排除部分。刚体
碰撞体
Input 输入
The guide above is recommended for understanding of how input works. Below are the 'quick' steps needed:
建议使用上述指南来了解 input 的工作原理。以下是所需的“快速”步骤:
- If using InputSystem (new Unity input package) add the following components to any object in the scene, e.g. SceneManager:
如果使用 InputSystem(新的 Unity 输入包),请将以下组件添加到场景中的任何对象,例如 SceneManager: - If using InputManager (old/classic Unity input) add the following components to any object in the scene, e.g. SceneManager:
如果使用 InputManager(旧/经典 Unity 输入),请将以下组件添加到场景中的任何对象,例如 SceneManager:
Cameras 相机
- Create an empty as a child of the vehicle and name it Cameras. Add a CameraChanger to it.
GameObject
创建一个空的车辆作为车辆的子项,并将其命名为 Cameras。向其添加 CameraChanger。游戏对象
- Add a as a child of the Cameras object (right click ⇒ Camera) and attach CameraMouseDrag component to it. Assign the vehicle as .
Camera
Target
添加 Cameras 对象的子对象(右键单击 Camera),并将 CameraMouseDrag 组件附加到⇒。将车辆指定为 。Camera
Target (摄像机目标)
- The CameraMouseDrag script is not required. Any camera, including Cinemachine ones, can be used with the CameraChanger.
不需要 CameraMouseDrag 脚本。任何摄像机,包括 Cinemachine 摄像机,都可以与 CameraChanger 一起使用。
VehicleController 车辆控制器
- Add component to the vehicle root - where the is.
VehicleController
Rigidbody
将组件添加到车辆根 - 其中的位置。VehicleController
刚体
VehicleController
will automatically set up default values and automatically set up s, s and s. Check console for output.Differential
Wheel
WheelGroup
VehicleController
将自动设置默认值并自动设置 s、s 和 s。检查控制台的输出。差速轮
WheelGroup
- Go to tab and click on button to for automatic validity check.
Settings
Validate Setup
转到选项卡并单击按钮以进行自动有效性检查。设置
验证设置
- Press play. Vehicle will now function but will not respond to any user input.
按下播放键。车辆现在可以运行,但不会响应任何用户输入。
Assembly Definitions 程序集定义
This asset uses Assembly Definition (.asmdef) files. There are many benefits to assembly definitions but a downside is that the whole project needs to use them or they should not be used at all.
此资源使用程序集定义 (.asmdef) 文件。 程序集定义有很多好处,但缺点是整个项目都需要使用它们,或者根本不应该使用它们。
- If the project already uses assembly definitions accessing a script that belongs to this asset can be done by adding an reference to the assembly definition of the script that needs to reference the asset. E.g. to access VehicleController adding a NWH.VehiclePhysics2.VehicleController reference to MyProject.asmdef is required.
- If the project does not use assembly definitions simply remove all the .asmdef files from the asset after import.
Using LogitechSDK (which does not fature assembly definitions) will therefore require an addition of .asmdef file inside the LogitechSDK directory and a reference inside NWH.VehiclePhysics2.VehicleController or removal of all .asmdef files from the asset if you do not wish to use assembly definitions.
Video Tutorials
These videos have been created by Game Dev Project and are not official tutorials but they might help with the setup. Reading the documentation is still highly recommended.
Getting started with NWH Vehicle Physics 2 - Unity Asset Tutorial
Model to Driveable in Under 60 Seconds - NWH Vehicle Physics 2 for Unity