# Rally Rush: godot::CarPlayer Class Reference

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

Sandboxed subclass of CarPhysics. More...

`#include <car_player.hpp>`

Inheritance diagram for godot::CarPlayer:

## Public Member Functions

virtual void | _ready () override
| Get the required child nodes.
virtual void | _process (double delta_time) override
| Update powerup and grace period timers. As well as the camera position.
virtual void | setup_player_input (PlayerInput *input) override
| Initialize player input callbacks.
virtual void | spawn_at_position (Transform3D const &transform) override
| Place player at initial position Called from the GameRoot3D of the godot-cpp-utils library.
virtual Node * | to_node () override
| Convert to node.
void | on_steer (Ref< InputEvent > event, float value)
| Input callback for the steering axis.
void | on_brake (Ref< InputEvent > event, float value)
| Input callback for the brake key.
void | on_accelerate (Ref< InputEvent > event, float value)
| Input callback for the accelerate key.
void | damage ()
| Take 1 damage.
void | destroy_all_powerups ()
| Destroy all children of roof_slot.
void | activate_powerup (Ref< PackedScene > scene)
| Destroy all children and activate a new powerup.
void | activate_turret ()
| Destroy all powerups and spawn a turret.
void | activate_beacon ()
| Destroy all powerups and spawn a beacon.
void | activate_shield ()
| Destroy all powerups and spawn a shield.
void | set_turret_scene (Ref< PackedScene > scene)
| The object representing the turret pickup.
Ref< PackedScene > | get_turret_scene () const
| The object representing the turret pickup.
void | set_beacon_scene (Ref< PackedScene > scene)
| The object representing the beacon pickup.
Ref< PackedScene > | get_beacon_scene () const
| The object representing the beacon pickup.
void | set_shield_scene (Ref< PackedScene > scene)
| The object representing the shield pickup.
Ref< PackedScene > | get_shield_scene () const
| The object representing the shield pickup.
Public Member Functions inherited from godot::CarPhysics
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.

## Private Member Functions

| GDCLASS (CarPlayer, CarPhysics)

## Static Private Member Functions

static void | _bind_methods ()
| Register editor properties and damage function.

## Private Attributes

int | health {5}
| Amount of hits the player's car can still take.
double | end_of_powerup {0.0}
| The time at which the current powerup will be deactivated.
bool | takes_damage {true}
| If false, the car will be invincible.
float | grace_timer_end {0.f}
| The time at which the current grace period will end.
Node3D * | roof_slot {nullptr}
| The parent of any pickup models.
Camera3D * | camera {nullptr}
| The camera.
Ref< PackedScene > | turret
| The roof turret powerup scene.
Ref< PackedScene > | beacon
| The hacking beacon powerup scene.
Ref< PackedScene > | shield
| The ramming shield powerup scene.
float const | max_speed {40.f}
| Target speed when accelerate is pressed.
float const | steering_factor {0.7f}
| Amount of steering to apply based on input.
float const | powerup_duration {10.f}
| Duration of a powerup after it is picked up.
float const | camera_distance {4.f}
| Distance from the pivot the camera should be at.
float const | camera_height {2.f}
| Height the camera should be at relative to the pivot.
float const | camera_fullspeed_fov {90.f}
| The FOV of the camera when the car is traveling at max_speed.
float const | camera_stopped_fov {70.f}
| FOV of the camera when the car is not moving.
float const | fov_lerp_delta {40.f}
| Speed in degrees-per-second that the camera FOV can change at.
float const | grace_time {1.f}
| Amount of time the player should be invincible after being hit.
float const | grace_time_flash {0.1f}
| Interval at which the car's model should flash while invincible after being hit.

## Additional Inherited Members

Protected Member Functions inherited from godot::CarPhysics
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.

## Detailed Description

Sandboxed subclass of CarPhysics.

Uses PlayerInput callbacks to drive the car. And updates the camera's position to show the action better. Inherits from IPlayer to be spawnable by the GameRoot3D and to be assigned a PlayerInput instance.

## Member Function Documentation

## _bind_methods()

void godot::CarPlayer::_bind_methods | ( |  | ) |

staticprivate

Register editor properties and damage function.

## _process()

void godot::CarPlayer::_process | ( | double | delta_time | ) |

overridevirtual

Update powerup and grace period timers. As well as the camera position.

## _ready()

void godot::CarPlayer::_ready | ( |  | ) |

overridevirtual

Get the required child nodes.

## activate_beacon()

void godot::CarPlayer::activate_beacon | ( |  | ) |

Destroy all powerups and spawn a beacon.

## activate_powerup()

void godot::CarPlayer::activate_powerup | ( | Ref< PackedScene > | scene | ) |

Destroy all children and activate a new powerup.

## activate_shield()

void godot::CarPlayer::activate_shield | ( |  | ) |

Destroy all powerups and spawn a shield.

## activate_turret()

void godot::CarPlayer::activate_turret | ( |  | ) |

Destroy all powerups and spawn a turret.

## damage()

void godot::CarPlayer::damage | ( |  | ) |

Take 1 damage.

## destroy_all_powerups()

void godot::CarPlayer::destroy_all_powerups | ( |  | ) |

Destroy all children of roof_slot.

## GDCLASS()

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

private

## get_beacon_scene()

Ref< PackedScene > godot::CarPlayer::get_beacon_scene | ( |  | ) | const

The object representing the beacon pickup.

## get_shield_scene()

Ref< PackedScene > godot::CarPlayer::get_shield_scene | ( |  | ) | const

The object representing the shield pickup.

## get_turret_scene()

Ref< PackedScene > godot::CarPlayer::get_turret_scene | ( |  | ) | const

The object representing the turret pickup.

## on_accelerate()

void godot::CarPlayer::on_accelerate | ( | Ref< InputEvent > | event,
|  | float | value
| ) |  |

Input callback for the accelerate key.

## on_brake()

void godot::CarPlayer::on_brake | ( | Ref< InputEvent > | event,
|  | float | value
| ) |  |

Input callback for the brake key.

## on_steer()

void godot::CarPlayer::on_steer | ( | Ref< InputEvent > | event,
|  | float | value
| ) |  |

Input callback for the steering axis.

## set_beacon_scene()

void godot::CarPlayer::set_beacon_scene | ( | Ref< PackedScene > | scene | ) |

The object representing the beacon pickup.

## set_shield_scene()

void godot::CarPlayer::set_shield_scene | ( | Ref< PackedScene > | scene | ) |

The object representing the shield pickup.

## set_turret_scene()

void godot::CarPlayer::set_turret_scene | ( | Ref< PackedScene > | scene | ) |

The object representing the turret pickup.

## setup_player_input()

void godot::CarPlayer::setup_player_input | ( | PlayerInput * | input | ) |

overridevirtual

Initialize player input callbacks.

Parameters

  input | Reference to a PlayerInput node managed by the GameRoot3D from the godot-cpp-utils library.

## spawn_at_position()

void godot::CarPlayer::spawn_at_position | ( | Transform3D const & | transform | ) |

overridevirtual

Place player at initial position Called from the GameRoot3D of the godot-cpp-utils library.

Parameters

  transform | The location and orientation of the spawn point.

## to_node()

Node * godot::CarPlayer::to_node | ( |  | ) |

overridevirtual

Convert to node.

## Member Data Documentation

## beacon

Ref<PackedScene> godot::CarPlayer::beacon

private

The hacking beacon powerup scene.

## camera

Camera3D* godot::CarPlayer::camera {nullptr}

private

The camera.

## camera_distance

float const godot::CarPlayer::camera_distance {4.f}

private

Distance from the pivot the camera should be at.

## camera_fullspeed_fov

float const godot::CarPlayer::camera_fullspeed_fov {90.f}

private

The FOV of the camera when the car is traveling at max_speed.

## camera_height

float const godot::CarPlayer::camera_height {2.f}

private

Height the camera should be at relative to the pivot.

## camera_stopped_fov

float const godot::CarPlayer::camera_stopped_fov {70.f}

private

FOV of the camera when the car is not moving.

## end_of_powerup

double godot::CarPlayer::end_of_powerup {0.0}

private

The time at which the current powerup will be deactivated.

## fov_lerp_delta

float const godot::CarPlayer::fov_lerp_delta {40.f}

private

Speed in degrees-per-second that the camera FOV can change at.

## grace_time

float const godot::CarPlayer::grace_time {1.f}

private

Amount of time the player should be invincible after being hit.

## grace_time_flash

float const godot::CarPlayer::grace_time_flash {0.1f}

private

Interval at which the car's model should flash while invincible after being hit.

## grace_timer_end

float godot::CarPlayer::grace_timer_end {0.f}

private

The time at which the current grace period will end.

## health

int godot::CarPlayer::health {5}

private

Amount of hits the player's car can still take.

## max_speed

float const godot::CarPlayer::max_speed {40.f}

private

Target speed when accelerate is pressed.

## powerup_duration

float const godot::CarPlayer::powerup_duration {10.f}

private

Duration of a powerup after it is picked up.

## roof_slot

Node3D* godot::CarPlayer::roof_slot {nullptr}

private

The parent of any pickup models.

## shield

Ref<PackedScene> godot::CarPlayer::shield

private

The ramming shield powerup scene.

## steering_factor

float const godot::CarPlayer::steering_factor {0.7f}

private

Amount of steering to apply based on input.

## takes_damage

bool godot::CarPlayer::takes_damage {true}

private

If false, the car will be invincible.

## turret

Ref<PackedScene> godot::CarPlayer::turret

private

The roof turret powerup scene.

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

- src/car_player.hpp
- src/car_player.cpp