VehicleBody

Inherits: RigidBody < PhysicsBody < CollisionObject < Spatial < Node < Object

Physics body that simulates the behavior of a car.

Description

This node implements all the physics logic needed to simulate a car. It is based on the raycast vehicle system commonly found in physics engines. You will need to add a CollisionShape for the main body of your vehicle and add VehicleWheel nodes for the wheels. You should also add a MeshInstance to this node for the 3D model of your car but this model should not include meshes for the wheels. You should control the vehicle by using the brake, engine_force, and steering properties and not change the position or orientation of this node directly.

Note: The origin point of your VehicleBody will determine the center of gravity of your vehicle so it is better to keep this low and move the CollisionShape and MeshInstance upwards.

Properties

floatbrake0.0
floatengine_force0.0
floatmassO: 40.0
floatsteering0.0
floatweightO: 392.0

Property Descriptions

Default0.0
Setterset_brake(value)
Getterget_brake()

Slows down the vehicle by applying a braking force. The vehicle is only slowed down if the wheels are in contact with a surface. The force you need to apply to adequately slow down your vehicle depends on the RigidBody.mass of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 – 30 range for hard braking.


Default0.0
Setterset_engine_force(value)
Getterget_engine_force()

Accelerates the vehicle by applying an engine force. The vehicle is only speed up if the wheels that have VehicleWheel.use_as_traction set to true and are in contact with a surface. The RigidBody.mass of the vehicle has an effect on the acceleration of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 – 50 range for acceleration.

Note: The simulation does not take the effect of gears into account, you will need to add logic for this if you wish to simulate gears.

A negative value will result in the vehicle reversing.


Default0.0
Setterset_steering(value)
Getterget_steering()

The steering angle for the vehicle. Setting this to a non-zero value will result in the vehicle turning when it’s moving. Wheels that have VehicleWheel.use_as_steering set to true will automatically be rotated.

doradoro's advice! Getters and Setters will be deprecated! Avoid their use!

Disclaimer: This page has been automaticaly and directly extracted from the official Godot Docs website, the 2020-03-07 at 01:42:08. It's the English Stable version because it's what most Godot users should use. The Copyright owners are Juan Linietsky, Ariel Manzur and the Godot community. CC-BY 3.0. Thanks for your patience and generosity.