virtualx-engine-docs/_sources/classes/class_vehiclebody.rst.txt
2024-10-23 09:41:33 -07:00

120 lines
7 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/VehicleBody.xml.
.. _class_VehicleBody:
VehicleBody
===========
**Inherits:** :ref:`RigidBody<class_RigidBody>` **<** :ref:`PhysicsBody<class_PhysicsBody>` **<** :ref:`CollisionObject<class_CollisionObject>` **<** :ref:`Spatial<class_Spatial>` **<** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
Physics body that simulates the behavior of a car.
.. rst-class:: classref-introduction-group
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 :ref:`CollisionShape<class_CollisionShape>` for the main body of your vehicle and add :ref:`VehicleWheel<class_VehicleWheel>` nodes for the wheels. You should also add a :ref:`MeshInstance<class_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 :ref:`brake<class_VehicleBody_property_brake>`, :ref:`engine_force<class_VehicleBody_property_engine_force>`, and :ref:`steering<class_VehicleBody_property_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 :ref:`CollisionShape<class_CollisionShape>` and :ref:`MeshInstance<class_MeshInstance>` upwards.
\ **Note:** This class has known issues and isn't designed to provide realistic 3D vehicle physics. If you want advanced vehicle physics, you will probably have to write your own physics integration using another :ref:`PhysicsBody<class_PhysicsBody>` class.
\ **Warning:** With a non-uniform scale this node will probably not function as expected. Please make sure to keep its scale uniform (i.e. the same on all axes), and change the size(s) of its collision shape(s) instead.
.. rst-class:: classref-introduction-group
Tutorials
---------
- `3D Truck Town Demo <https://godotengine.org/asset-library/asset/524>`__
.. rst-class:: classref-reftable-group
Properties
----------
.. table::
:widths: auto
+---------------------------+--------------------------------------------------------------+-------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`brake<class_VehicleBody_property_brake>` | ``0.0`` |
+---------------------------+--------------------------------------------------------------+-------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`engine_force<class_VehicleBody_property_engine_force>` | ``0.0`` |
+---------------------------+--------------------------------------------------------------+-------------------------------------------------------------------------+
| :ref:`float<class_float>` | mass | ``40.0`` (overrides :ref:`RigidBody<class_RigidBody_property_mass>`) |
+---------------------------+--------------------------------------------------------------+-------------------------------------------------------------------------+
| :ref:`float<class_float>` | :ref:`steering<class_VehicleBody_property_steering>` | ``0.0`` |
+---------------------------+--------------------------------------------------------------+-------------------------------------------------------------------------+
| :ref:`float<class_float>` | weight | ``392.0`` (overrides :ref:`RigidBody<class_RigidBody_property_weight>`) |
+---------------------------+--------------------------------------------------------------+-------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Property Descriptions
---------------------
.. _class_VehicleBody_property_brake:
.. rst-class:: classref-property
:ref:`float<class_float>` **brake** = ``0.0``
.. rst-class:: classref-property-setget
- void **set_brake** **(** :ref:`float<class_float>` value **)**
- :ref:`float<class_float>` **get_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 :ref:`RigidBody.mass<class_RigidBody_property_mass>` of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 30 range for hard braking.
.. rst-class:: classref-item-separator
----
.. _class_VehicleBody_property_engine_force:
.. rst-class:: classref-property
:ref:`float<class_float>` **engine_force** = ``0.0``
.. rst-class:: classref-property-setget
- void **set_engine_force** **(** :ref:`float<class_float>` value **)**
- :ref:`float<class_float>` **get_engine_force** **(** **)**
Accelerates the vehicle by applying an engine force. The vehicle is only sped up if the wheels that have :ref:`VehicleWheel.use_as_traction<class_VehicleWheel_property_use_as_traction>` set to ``true`` and are in contact with a surface. The :ref:`RigidBody.mass<class_RigidBody_property_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.
.. rst-class:: classref-item-separator
----
.. _class_VehicleBody_property_steering:
.. rst-class:: classref-property
:ref:`float<class_float>` **steering** = ``0.0``
.. rst-class:: classref-property-setget
- void **set_steering** **(** :ref:`float<class_float>` value **)**
- :ref:`float<class_float>` **get_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 :ref:`VehicleWheel.use_as_steering<class_VehicleWheel_property_use_as_steering>` set to ``true`` will automatically be rotated.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`