Rally Rush
|
Sandboxed subclass of CarPhysics. More...
#include <car_player.hpp>
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. | |
![]() | |
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 | |
![]() | |
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. | |
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.
|
staticprivate |
Register editor properties and damage function.
|
overridevirtual |
Update powerup and grace period timers. As well as the camera position.
|
overridevirtual |
Get the required child nodes.
void godot::CarPlayer::activate_beacon | ( | ) |
Destroy all powerups and spawn a beacon.
void godot::CarPlayer::activate_powerup | ( | Ref< PackedScene > | scene | ) |
Destroy all children and activate a new powerup.
void godot::CarPlayer::activate_shield | ( | ) |
Destroy all powerups and spawn a shield.
void godot::CarPlayer::activate_turret | ( | ) |
Destroy all powerups and spawn a turret.
void godot::CarPlayer::damage | ( | ) |
Take 1 damage.
void godot::CarPlayer::destroy_all_powerups | ( | ) |
Destroy all children of roof_slot.
|
private |
Ref< PackedScene > godot::CarPlayer::get_beacon_scene | ( | ) | const |
The object representing the beacon pickup.
Ref< PackedScene > godot::CarPlayer::get_shield_scene | ( | ) | const |
The object representing the shield pickup.
Ref< PackedScene > godot::CarPlayer::get_turret_scene | ( | ) | const |
The object representing the turret pickup.
void godot::CarPlayer::on_accelerate | ( | Ref< InputEvent > | event, |
float | value | ||
) |
Input callback for the accelerate key.
void godot::CarPlayer::on_brake | ( | Ref< InputEvent > | event, |
float | value | ||
) |
Input callback for the brake key.
void godot::CarPlayer::on_steer | ( | Ref< InputEvent > | event, |
float | value | ||
) |
Input callback for the steering axis.
void godot::CarPlayer::set_beacon_scene | ( | Ref< PackedScene > | scene | ) |
The object representing the beacon pickup.
void godot::CarPlayer::set_shield_scene | ( | Ref< PackedScene > | scene | ) |
The object representing the shield pickup.
void godot::CarPlayer::set_turret_scene | ( | Ref< PackedScene > | scene | ) |
The object representing the turret pickup.
|
overridevirtual |
Initialize player input callbacks.
input | Reference to a PlayerInput node managed by the GameRoot3D from the godot-cpp-utils library. |
|
overridevirtual |
Place player at initial position Called from the GameRoot3D of the godot-cpp-utils library.
transform | The location and orientation of the spawn point. |
|
overridevirtual |
Convert to node.
|
private |
The hacking beacon powerup scene.
|
private |
The camera.
|
private |
Distance from the pivot the camera should be at.
|
private |
The FOV of the camera when the car is traveling at max_speed.
|
private |
Height the camera should be at relative to the pivot.
|
private |
FOV of the camera when the car is not moving.
|
private |
The time at which the current powerup will be deactivated.
|
private |
Speed in degrees-per-second that the camera FOV can change at.
|
private |
Amount of time the player should be invincible after being hit.
|
private |
Interval at which the car's model should flash while invincible after being hit.
|
private |
The time at which the current grace period will end.
|
private |
Amount of hits the player's car can still take.
|
private |
Target speed when accelerate is pressed.
|
private |
Duration of a powerup after it is picked up.
|
private |
The parent of any pickup models.
|
private |
The ramming shield powerup scene.
|
private |
Amount of steering to apply based on input.
|
private |
If false, the car will be invincible.
|
private |
The roof turret powerup scene.