Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

VehicleBody3D

繼承: RigidBody3D < PhysicsBody3D < CollisionObject3D < Node3D < Node < Object

類比汽車行為的 3D 物理體。

說明

This physics body implements all the physics logic needed to simulate a car. It is based on the raycast vehicle system commonly found in physics engines. Aside from a CollisionShape3D for the main body of the vehicle, you must also add a VehicleWheel3D node for each wheel. You should also add a MeshInstance3D to this node for the 3D model of the vehicle, but this model should generally not include meshes for the wheels. You can control the vehicle by using the brake, engine_force, and steering properties. The position or orientation of this node shouldn't be changed directly.

Note: The local forward for this node is Vector3.MODEL_FRONT.

Note: The origin point of your VehicleBody3D will determine the center of gravity of your vehicle. To make the vehicle more grounded, the origin point is usually kept low, moving the CollisionShape3D and MeshInstance3D upwards.

Note: This class has known issues and isn't designed to provide realistic 3D vehicle physics. If you want advanced vehicle physics, you may have to write your own physics integration using CharacterBody3D or RigidBody3D.

教學

屬性

float

brake

0.0

float

engine_force

0.0

float

mass

40.0 (overrides RigidBody3D)

float

steering

0.0


屬性說明

float brake = 0.0 🔗

通過施加一個制動力使車輛減速。只有當車輪接觸到表面時,車輛才會減速。使車輛充分減速所需的力,取決於車輛的 RigidBody3D.mass。對於一個品質被設定為 1000 的車輛,嘗試使用 25 - 30 範圍內的值進行緊急制動。


float engine_force = 0.0 🔗

  • void set_engine_force(value: float)

  • float get_engine_force()

通過施加一個引擎力來加速車輛。只有當 VehicleWheel3D.use_as_traction 被設定為 true 的車輪與表面接觸時,車輛才會加速。車輛的 RigidBody3D.mass 對車輛的加速度有影響。對於品質被設定為 1000 的車輛,請嘗試使用 25 - 50 範圍內的加速度值。

注意:模擬沒有考慮齒輪的影響,如果想要類比齒輪,需要為其新增邏輯。

負值將導致車輛倒車。


float steering = 0.0 🔗

  • void set_steering(value: float)

  • float get_steering()

車輛的轉向角。將該屬性設定為非零值將導致車輛在移動時轉彎。VehicleWheel3D.use_as_steering 設定為 true 的車輪將自動旋轉。

注意:該屬性在屬性檢視器中以度為單位進行編輯。在程式碼中,該屬性以弧度單位設置。