Rally Rush
|
Subclass Sandbox for car physics. Uses _integrate_forces and local_velocity to abstract the behaviour of a physical car. More...
#include <car_physics.hpp>
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} |
Subclass Sandbox for car physics. Uses _integrate_forces and local_velocity to abstract the behaviour of a physical car.
|
staticprivate |
Registers functions and properties.
|
overridevirtual |
Enable _integrate_forces, fetch child nodes, and setup contact monitoring.
Reimplemented in godot::EnemyCar.
|
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.
|
overridevirtual |
Fixed-interval process function. Split into process_oversteer and process_understeer.
|
protected |
evaluate the oversteer curve with a speed, taking *_x_scale into account
|
protected |
evaluate the understeer curve with a speed, taking *_x_scale into account
|
private |
float godot::CarPhysics::get_acceleration | ( | ) | const |
The base engine acceleration of this car.
bool godot::CarPhysics::get_brake | ( | ) | const |
True if the hand-brake is currently active.
|
protected |
Returns acceleration, taking into account braking, throttle, and handbrake.
float godot::CarPhysics::get_current_speed | ( | ) | const |
The current forward velocity (local_velocity.z)
float godot::CarPhysics::get_current_steering | ( | ) | const |
The current steering input.
float godot::CarPhysics::get_engine_brake_force | ( | ) | const |
The base engine braking force of this car.
float godot::CarPhysics::get_handbrake_force | ( | ) | const |
The amount of braking force applied by the handbrake.
float godot::CarPhysics::get_handbrake_oversteer | ( | ) | const |
The modifier applied to oversteering when the handbrake is active.
Vector3 godot::CarPhysics::get_local_velocity | ( | ) | const |
Public getter for current local velocity.
float godot::CarPhysics::get_max_slide_speed | ( | ) | const |
The maximum sideways speed that can be reached while drifting.
float godot::CarPhysics::get_oversteer_brake_penalty | ( | ) | const |
Modifier applied to brake force when oversteering.
Ref< Curve > godot::CarPhysics::get_oversteer_curve | ( | ) | const |
The base curve used for oversteering.
float godot::CarPhysics::get_oversteer_curve_x_scale | ( | ) | const |
The amount of speed represented by x=1 on the oversteer curve.
float godot::CarPhysics::get_oversteer_speed_penalty | ( | ) | const |
Deceleration applied to forward speed when oversteering.
float godot::CarPhysics::get_oversteer_steering_speed | ( | ) | const |
Base amount of steering applied while oversteering.
float godot::CarPhysics::get_slide_resistance | ( | ) | const |
Deceleration applied to sideways velocity.
float godot::CarPhysics::get_slide_speed_acceleration | ( | ) | const |
The sideways acceleration applied when drifting.
float godot::CarPhysics::get_steering_inward_speed | ( | ) | const |
Target amount of velocity towards the centre of a turn while steering.
float godot::CarPhysics::get_target_speed | ( | ) | const |
The target speed.
float godot::CarPhysics::get_traction_recovery_speed | ( | ) | const |
The speed at which the car will return to regular traction after under- or oversteering.
|
protected |
Returns the maximum speed modified by under/oversteer.
Ref< Curve > godot::CarPhysics::get_understeer_curve | ( | ) | const |
The base curve used for understeering.
float godot::CarPhysics::get_understeer_curve_x_scale | ( | ) | const |
The amount of speed represented by x=1 on the understeer curve.
|
protected |
Apply velocity along local z. Accelerates towards value returned by get_true_target_speed at get_current_acceleration m/s^2.
|
protected |
Integrate oversteering to local_velocity to allow drifting.
|
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.
|
protected |
Returns true if there is at least one contact with either of the wheels.
Vector3 godot::CarPhysics::local_to_world_velocity | ( | ) | const |
transform the current local_velocity to world coordinates
|
protected |
Detect that an object started colliding with the wheels.
|
protected |
Detect that an object lost contact with the wheels.
void godot::CarPhysics::process_oversteer | ( | double | delta_time | ) |
Process the current_oversteer member variable.
void godot::CarPhysics::process_understeer | ( | double | delta_time | ) |
Process the current_understeer member variable.
void godot::CarPhysics::set_acceleration | ( | float | value | ) |
The base engine acceleration of this car.
void godot::CarPhysics::set_brake | ( | bool | value | ) |
True if the hand-brake is currently active.
void godot::CarPhysics::set_current_steering | ( | float | steering | ) |
The current steering input.
void godot::CarPhysics::set_engine_brake_force | ( | float | value | ) |
The base engine braking force of this car.
void godot::CarPhysics::set_handbrake_force | ( | float | value | ) |
The amount of braking force applied by the handbrake.
void godot::CarPhysics::set_handbrake_oversteer | ( | float | value | ) |
The modifier applied to oversteering when the handbrake is active.
void godot::CarPhysics::set_max_slide_speed | ( | float | value | ) |
The maximum sideways speed that can be reached while drifting.
void godot::CarPhysics::set_oversteer_brake_penalty | ( | float | value | ) |
Modifier applied to brake force when oversteering.
void godot::CarPhysics::set_oversteer_curve | ( | Ref< Curve > | curve | ) |
The base curve used for oversteering.
void godot::CarPhysics::set_oversteer_curve_x_scale | ( | float | scale | ) |
The amount of speed represented by x=1 on the oversteer curve.
void godot::CarPhysics::set_oversteer_speed_penalty | ( | float | value | ) |
Deceleration applied to forward speed when oversteering.
void godot::CarPhysics::set_oversteer_steering_speed | ( | float | value | ) |
Modifier applied to brake force when oversteering.
void godot::CarPhysics::set_slide_resistance | ( | float | value | ) |
Deceleration applied to sideways velocity.
void godot::CarPhysics::set_slide_speed_acceleration | ( | float | value | ) |
The sideways acceleration applied when drifting.
void godot::CarPhysics::set_steering_inward_speed | ( | float | value | ) |
Target amount of velocity towards the centre of a turn while steering.
void godot::CarPhysics::set_target_speed | ( | float | target | ) |
The target 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.
void godot::CarPhysics::set_understeer_curve | ( | Ref< Curve > | curve | ) |
The base curve used for understeering.
void godot::CarPhysics::set_understeer_curve_x_scale | ( | float | scale | ) |
The amount of speed represented by x=1 on the understeer curve.
Vector3 godot::CarPhysics::world_to_local_velocity | ( | ) | const |
transform the current world velocity to local coordinates
|
private |
|
private |
|
private |
While true, the handbrake is on.
|
private |
|
private |
Current steering input.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Acceleration at the end of the integration step of the last frame.
|
private |
Velocity relative to the local transform.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Target value for local_velocity.z.
|
private |
|
private |
|
private |
|
private |