# Rally Rush: godot::CarPhysics Class Reference

Loading...
Searching...
No Matches
godot::CarPhysics Class Reference

Subclass Sandbox for car physics. Uses _integrate_forces and local_velocity to abstract the behaviour of a physical car. More...

`#include <car_physics.hpp>`

Inheritance diagram for godot::CarPhysics:

## Public Member Functions

virtual void | _enter_tree () override
| Enable _integrate_forces, fetch child nodes, and setup contact monitoring.
virtual void | _physics_process (double delta_time) override
| Fixed-interval process function. Split into process_oversteer and process_understeer.
void | process_oversteer (double delta_time)
| Process the current_oversteer member variable.
void | process_understeer (double delta_time)
| Process the current_understeer member variable.
virtual void | _integrate_forces (PhysicsDirectBodyState3D *state) override
| Custom force integrator. Split into integrate_steering, integrate_engine_acceleration and integrate_oversteer. After calling other integrate_* functions, applies local_velocity to state.velocity.
Vector3 | get_local_velocity () const
| Public getter for current local velocity.
Vector3 | local_to_world_velocity () const
| transform the current local_velocity to world coordinates
Vector3 | world_to_local_velocity () const
| transform the current world velocity to local coordinates
float | get_current_speed () const
| The current forward velocity (local_velocity.z)
void | set_target_speed (float target)
| The target speed.
float | get_target_speed () const
| The target speed.
void | set_current_steering (float steering)
| The current steering input.
float | get_current_steering () const
| The current steering input.
void | set_brake (bool value)
| True if the hand-brake is currently active.
bool | get_brake () const
| True if the hand-brake is currently active.
void | set_oversteer_curve (Ref< Curve > curve)
| The base curve used for oversteering.
Ref< Curve > | get_oversteer_curve () const
| The base curve used for oversteering.
void | set_oversteer_curve_x_scale (float scale)
| The amount of speed represented by x=1 on the oversteer curve.
float | get_oversteer_curve_x_scale () const
| The amount of speed represented by x=1 on the oversteer curve.
void | set_understeer_curve (Ref< Curve > curve)
| The base curve used for understeering.
Ref< Curve > | get_understeer_curve () const
| The base curve used for understeering.
void | set_understeer_curve_x_scale (float scale)
| The amount of speed represented by x=1 on the understeer curve.
float | get_understeer_curve_x_scale () const
| The amount of speed represented by x=1 on the understeer curve.
void | set_acceleration (float value)
| The base engine acceleration of this car.
float | get_acceleration () const
| The base engine acceleration of this car.
void | set_engine_brake_force (float value)
| The base engine braking force of this car.
float | get_engine_brake_force () const
| The base engine braking force of this car.
void | set_handbrake_force (float value)
| The amount of braking force applied by the handbrake.
float | get_handbrake_force () const
| The amount of braking force applied by the handbrake.
void | set_handbrake_oversteer (float value)
| The modifier applied to oversteering when the handbrake is active.
float | get_handbrake_oversteer () const
| The modifier applied to oversteering when the handbrake is active.
void | set_traction_recovery_speed (float value)
| The speed at which the car will return to regular traction after under- or oversteering.
float | get_traction_recovery_speed () const
| The speed at which the car will return to regular traction after under- or oversteering.
void | set_max_slide_speed (float value)
| The maximum sideways speed that can be reached while drifting.
float | get_max_slide_speed () const
| The maximum sideways speed that can be reached while drifting.
void | set_slide_speed_acceleration (float value)
| The sideways acceleration applied when drifting.
float | get_slide_speed_acceleration () const
| The sideways acceleration applied when drifting.
void | set_oversteer_speed_penalty (float value)
| Deceleration applied to forward speed when oversteering.
float | get_oversteer_speed_penalty () const
| Deceleration applied to forward speed when oversteering.
void | set_oversteer_brake_penalty (float value)
| Modifier applied to brake force when oversteering.
float | get_oversteer_brake_penalty () const
| Modifier applied to brake force when oversteering.
void | set_oversteer_steering_speed (float value)
| Modifier applied to brake force when oversteering.
float | get_oversteer_steering_speed () const
| Base amount of steering applied while oversteering.
void | set_slide_resistance (float value)
| Deceleration applied to sideways velocity.
float | get_slide_resistance () const
| Deceleration applied to sideways velocity.
void | set_steering_inward_speed (float value)
| Target amount of velocity towards the centre of a turn while steering.
float | get_steering_inward_speed () const
| Target amount of velocity towards the centre of a turn while steering.

## Protected Member Functions

void | integrate_steering (PhysicsDirectBodyState3D *state)
| Integrate steering into angular and local x velocities. As a side-effect this also applies sliding resistance and sliding recovery. Also detects crashes to avoid glitchy behaviour when accelerating into a wall.
void | integrate_engine_acceleration (PhysicsDirectBodyState3D *state)
| Apply velocity along local z. Accelerates towards value returned by get_true_target_speed at get_current_acceleration m/s^2.
void | integrate_oversteer (PhysicsDirectBodyState3D *state)
| Integrate oversteering to local_velocity to allow drifting.
void | on_body_shape_entered (RID body_rid, Node *node, int body_shape_index, int local_shape_index)
| Detect that an object started colliding with the wheels.
void | on_body_shape_exited (RID body_rid, Node *node, int body_shape_index, int local_shape_index)
| Detect that an object lost contact with the wheels.
float | evaluate_oversteer_curve (float speed) const
| evaluate the oversteer curve with a speed, taking *_x_scale into account
float | evaluate_understeer_curve (float speed) const
| evaluate the understeer curve with a speed, taking *_x_scale into account
float | get_true_target_speed () const
| Returns the maximum speed modified by under/oversteer.
bool | is_grounded () const
| Returns true if there is at least one contact with either of the wheels.
float | get_current_acceleration () const
| Returns acceleration, taking into account braking, throttle, and handbrake.

## Private Member Functions

| GDCLASS (CarPhysics, RigidBody3D)

## Static Private Member Functions

static void | _bind_methods ()
| Registers functions and properties.

## Private Attributes

Vector3 | last_velocity {0.f, 0.f, 0.f}
| Acceleration at the end of the integration step of the last frame.
Vector3 | local_velocity {0.f, 0.f, 0.f}
| Velocity relative to the local transform.
float | target_speed {0.f}
| Target value for local_velocity.z.
float | current_steering {0.f}
| Current steering input.
bool | brake {false}
| While true, the handbrake is on.
Ref< Curve > | oversteer_curve {}
float | oversteer_curve_x_scale {50.f}
Ref< Curve > | understeer_curve {}
float | understeer_curve_x_scale {50.f}
float | acceleration {20.f}
float | engine_brake_force {30.f}
float | handbrake_force {40.f}
float | handbrake_oversteer {1.f}
float | traction_recovery_speed {1.f}
float | max_slide_speed {20.f}
float | slide_speed_acceleration {0.05f}
float | oversteer_speed_penalty {5.f}
float | oversteer_brake_penalty {0.25f}
float | oversteer_steering_speed {0.7f}
float | understeer_speed_penalty {3.f}
float | slide_resistance {20.f}
float | steering_inward_speed {0.1f}
HashSet< Node * > | grounded_objects {}
CollisionShape3D * | front_wheels {nullptr}
CollisionShape3D * | back_wheels {nullptr}
float | current_understeer {0.f}
float | current_oversteer {0.f}

## Detailed Description

Subclass Sandbox for car physics. Uses _integrate_forces and local_velocity to abstract the behaviour of a physical car.

## Member Function Documentation

## _bind_methods()

void godot::CarPhysics::_bind_methods | ( |  | ) |

staticprivate

Registers functions and properties.

## _enter_tree()

void godot::CarPhysics::_enter_tree | ( |  | ) |

overridevirtual

Enable _integrate_forces, fetch child nodes, and setup contact monitoring.

Reimplemented in godot::EnemyCar.

## _integrate_forces()

void godot::CarPhysics::_integrate_forces | ( | PhysicsDirectBodyState3D * | state | ) |

overridevirtual

Custom force integrator. Split into integrate_steering, integrate_engine_acceleration and integrate_oversteer. After calling other integrate_* functions, applies local_velocity to state.velocity.

## _physics_process()

void godot::CarPhysics::_physics_process | ( | double | delta_time | ) |

overridevirtual

Fixed-interval process function. Split into process_oversteer and process_understeer.

## evaluate_oversteer_curve()

float godot::CarPhysics::evaluate_oversteer_curve | ( | float | speed | ) | const

protected

evaluate the oversteer curve with a speed, taking *_x_scale into account

## evaluate_understeer_curve()

float godot::CarPhysics::evaluate_understeer_curve | ( | float | speed | ) | const

protected

evaluate the understeer curve with a speed, taking *_x_scale into account

## GDCLASS()

godot::CarPhysics::GDCLASS | ( | CarPhysics | ,
|  | RigidBody3D |
| ) |  |

private

## get_acceleration()

float godot::CarPhysics::get_acceleration | ( |  | ) | const

The base engine acceleration of this car.

## get_brake()

bool godot::CarPhysics::get_brake | ( |  | ) | const

True if the hand-brake is currently active.

## get_current_acceleration()

float godot::CarPhysics::get_current_acceleration | ( |  | ) | const

protected

Returns acceleration, taking into account braking, throttle, and handbrake.

## get_current_speed()

float godot::CarPhysics::get_current_speed | ( |  | ) | const

The current forward velocity (local_velocity.z)

## get_current_steering()

float godot::CarPhysics::get_current_steering | ( |  | ) | const

The current steering input.

## get_engine_brake_force()

float godot::CarPhysics::get_engine_brake_force | ( |  | ) | const

The base engine braking force of this car.

## get_handbrake_force()

float godot::CarPhysics::get_handbrake_force | ( |  | ) | const

The amount of braking force applied by the handbrake.

## get_handbrake_oversteer()

float godot::CarPhysics::get_handbrake_oversteer | ( |  | ) | const

The modifier applied to oversteering when the handbrake is active.

## get_local_velocity()

Vector3 godot::CarPhysics::get_local_velocity | ( |  | ) | const

Public getter for current local velocity.

## get_max_slide_speed()

float godot::CarPhysics::get_max_slide_speed | ( |  | ) | const

The maximum sideways speed that can be reached while drifting.

## get_oversteer_brake_penalty()

float godot::CarPhysics::get_oversteer_brake_penalty | ( |  | ) | const

Modifier applied to brake force when oversteering.

## get_oversteer_curve()

Ref< Curve > godot::CarPhysics::get_oversteer_curve | ( |  | ) | const

The base curve used for oversteering.

## get_oversteer_curve_x_scale()

float godot::CarPhysics::get_oversteer_curve_x_scale | ( |  | ) | const

The amount of speed represented by x=1 on the oversteer curve.

## get_oversteer_speed_penalty()

float godot::CarPhysics::get_oversteer_speed_penalty | ( |  | ) | const

Deceleration applied to forward speed when oversteering.

## get_oversteer_steering_speed()

float godot::CarPhysics::get_oversteer_steering_speed | ( |  | ) | const

Base amount of steering applied while oversteering.

## get_slide_resistance()

float godot::CarPhysics::get_slide_resistance | ( |  | ) | const

Deceleration applied to sideways velocity.

## get_slide_speed_acceleration()

float godot::CarPhysics::get_slide_speed_acceleration | ( |  | ) | const

The sideways acceleration applied when drifting.

## get_steering_inward_speed()

float godot::CarPhysics::get_steering_inward_speed | ( |  | ) | const

Target amount of velocity towards the centre of a turn while steering.

## get_target_speed()

float godot::CarPhysics::get_target_speed | ( |  | ) | const

The target speed.

## get_traction_recovery_speed()

float godot::CarPhysics::get_traction_recovery_speed | ( |  | ) | const

The speed at which the car will return to regular traction after under- or oversteering.

## get_true_target_speed()

float godot::CarPhysics::get_true_target_speed | ( |  | ) | const

protected

Returns the maximum speed modified by under/oversteer.

## get_understeer_curve()

Ref< Curve > godot::CarPhysics::get_understeer_curve | ( |  | ) | const

The base curve used for understeering.

## get_understeer_curve_x_scale()

float godot::CarPhysics::get_understeer_curve_x_scale | ( |  | ) | const

The amount of speed represented by x=1 on the understeer curve.

## integrate_engine_acceleration()

void godot::CarPhysics::integrate_engine_acceleration | ( | PhysicsDirectBodyState3D * | state | ) |

protected

Apply velocity along local z. Accelerates towards value returned by get_true_target_speed at get_current_acceleration m/s^2.

## integrate_oversteer()

void godot::CarPhysics::integrate_oversteer | ( | PhysicsDirectBodyState3D * | state | ) |

protected

Integrate oversteering to local_velocity to allow drifting.

## integrate_steering()

void godot::CarPhysics::integrate_steering | ( | PhysicsDirectBodyState3D * | state | ) |

protected

Integrate steering into angular and local x velocities. As a side-effect this also applies sliding resistance and sliding recovery. Also detects crashes to avoid glitchy behaviour when accelerating into a wall.

## is_grounded()

bool godot::CarPhysics::is_grounded | ( |  | ) | const

protected

Returns true if there is at least one contact with either of the wheels.

## local_to_world_velocity()

Vector3 godot::CarPhysics::local_to_world_velocity | ( |  | ) | const

transform the current local_velocity to world coordinates

## on_body_shape_entered()

void godot::CarPhysics::on_body_shape_entered | ( | RID | body_rid,
|  | Node * | node,
|  | int | body_shape_index,
|  | int | local_shape_index
| ) |  |

protected

Detect that an object started colliding with the wheels.

## on_body_shape_exited()

void godot::CarPhysics::on_body_shape_exited | ( | RID | body_rid,
|  | Node * | node,
|  | int | body_shape_index,
|  | int | local_shape_index
| ) |  |

protected

Detect that an object lost contact with the wheels.

## process_oversteer()

void godot::CarPhysics::process_oversteer | ( | double | delta_time | ) |

Process the current_oversteer member variable.

## process_understeer()

void godot::CarPhysics::process_understeer | ( | double | delta_time | ) |

Process the current_understeer member variable.

## set_acceleration()

void godot::CarPhysics::set_acceleration | ( | float | value | ) |

The base engine acceleration of this car.

## set_brake()

void godot::CarPhysics::set_brake | ( | bool | value | ) |

True if the hand-brake is currently active.

## set_current_steering()

void godot::CarPhysics::set_current_steering | ( | float | steering | ) |

The current steering input.

## set_engine_brake_force()

void godot::CarPhysics::set_engine_brake_force | ( | float | value | ) |

The base engine braking force of this car.

## set_handbrake_force()

void godot::CarPhysics::set_handbrake_force | ( | float | value | ) |

The amount of braking force applied by the handbrake.

## set_handbrake_oversteer()

void godot::CarPhysics::set_handbrake_oversteer | ( | float | value | ) |

The modifier applied to oversteering when the handbrake is active.

## set_max_slide_speed()

void godot::CarPhysics::set_max_slide_speed | ( | float | value | ) |

The maximum sideways speed that can be reached while drifting.

## set_oversteer_brake_penalty()

void godot::CarPhysics::set_oversteer_brake_penalty | ( | float | value | ) |

Modifier applied to brake force when oversteering.

## set_oversteer_curve()

void godot::CarPhysics::set_oversteer_curve | ( | Ref< Curve > | curve | ) |

The base curve used for oversteering.

## set_oversteer_curve_x_scale()

void godot::CarPhysics::set_oversteer_curve_x_scale | ( | float | scale | ) |

The amount of speed represented by x=1 on the oversteer curve.

## set_oversteer_speed_penalty()

void godot::CarPhysics::set_oversteer_speed_penalty | ( | float | value | ) |

Deceleration applied to forward speed when oversteering.

## set_oversteer_steering_speed()

void godot::CarPhysics::set_oversteer_steering_speed | ( | float | value | ) |

Modifier applied to brake force when oversteering.

## set_slide_resistance()

void godot::CarPhysics::set_slide_resistance | ( | float | value | ) |

Deceleration applied to sideways velocity.

## set_slide_speed_acceleration()

void godot::CarPhysics::set_slide_speed_acceleration | ( | float | value | ) |

The sideways acceleration applied when drifting.

## set_steering_inward_speed()

void godot::CarPhysics::set_steering_inward_speed | ( | float | value | ) |

Target amount of velocity towards the centre of a turn while steering.

## set_target_speed()

void godot::CarPhysics::set_target_speed | ( | float | target | ) |

The target speed.

## set_traction_recovery_speed()

void godot::CarPhysics::set_traction_recovery_speed | ( | float | value | ) |

The speed at which the car will return to regular traction after under- or oversteering.

## set_understeer_curve()

void godot::CarPhysics::set_understeer_curve | ( | Ref< Curve > | curve | ) |

The base curve used for understeering.

## set_understeer_curve_x_scale()

void godot::CarPhysics::set_understeer_curve_x_scale | ( | float | scale | ) |

The amount of speed represented by x=1 on the understeer curve.

## world_to_local_velocity()

Vector3 godot::CarPhysics::world_to_local_velocity | ( |  | ) | const

transform the current world velocity to local coordinates

## Member Data Documentation

## acceleration

float godot::CarPhysics::acceleration {20.f}

private

## back_wheels

CollisionShape3D* godot::CarPhysics::back_wheels {nullptr}

private

## brake

bool godot::CarPhysics::brake {false}

private

While true, the handbrake is on.

## current_oversteer

float godot::CarPhysics::current_oversteer {0.f}

private

## current_steering

float godot::CarPhysics::current_steering {0.f}

private

Current steering input.

## current_understeer

float godot::CarPhysics::current_understeer {0.f}

private

## engine_brake_force

float godot::CarPhysics::engine_brake_force {30.f}

private

## front_wheels

CollisionShape3D* godot::CarPhysics::front_wheels {nullptr}

private

## grounded_objects

HashSet<Node*> godot::CarPhysics::grounded_objects {}

private

## handbrake_force

float godot::CarPhysics::handbrake_force {40.f}

private

## handbrake_oversteer

float godot::CarPhysics::handbrake_oversteer {1.f}

private

## last_velocity

Vector3 godot::CarPhysics::last_velocity {0.f, 0.f, 0.f}

private

Acceleration at the end of the integration step of the last frame.

## local_velocity

Vector3 godot::CarPhysics::local_velocity {0.f, 0.f, 0.f}

private

Velocity relative to the local transform.

## max_slide_speed

float godot::CarPhysics::max_slide_speed {20.f}

private

## oversteer_brake_penalty

float godot::CarPhysics::oversteer_brake_penalty {0.25f}

private

## oversteer_curve

Ref<Curve> godot::CarPhysics::oversteer_curve {}

private

## oversteer_curve_x_scale

float godot::CarPhysics::oversteer_curve_x_scale {50.f}

private

## oversteer_speed_penalty

float godot::CarPhysics::oversteer_speed_penalty {5.f}

private

## oversteer_steering_speed

float godot::CarPhysics::oversteer_steering_speed {0.7f}

private

## slide_resistance

float godot::CarPhysics::slide_resistance {20.f}

private

## slide_speed_acceleration

float godot::CarPhysics::slide_speed_acceleration {0.05f}

private

## steering_inward_speed

float godot::CarPhysics::steering_inward_speed {0.1f}

private

## target_speed

float godot::CarPhysics::target_speed {0.f}

private

Target value for local_velocity.z.

## traction_recovery_speed

float godot::CarPhysics::traction_recovery_speed {1.f}

private

## understeer_curve

Ref<Curve> godot::CarPhysics::understeer_curve {}

private

## understeer_curve_x_scale

float godot::CarPhysics::understeer_curve_x_scale {50.f}

private

## understeer_speed_penalty

float godot::CarPhysics::understeer_speed_penalty {3.f}

private

The documentation for this class was generated from the following files:

- src/car_physics.hpp
- src/car_physics.cpp