feat: physics tweaks

This commit is contained in:
Sara 2024-05-21 08:46:47 +02:00
parent 4ec964e864
commit ba1545333a
4 changed files with 14 additions and 17 deletions

View file

@ -8,7 +8,7 @@
[ext_resource type="PackedScene" uid="uid://6qwqncti3xr2" path="res://Models/CarParts/SM_Veh_Hatch_01_Fenders_02.fbx" id="6_xu64x"]
[sub_resource type="Curve" id="Curve_dpk6q"]
_data = [Vector2(0.962441, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0]
_data = [Vector2(0.962441, 0), 0.0, 0.0, 0, 0, Vector2(1, 0.32967), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_htvme"]
@ -34,7 +34,6 @@ oversteer_curve = SubResource("Curve_dpk6q")
oversteer_curve_x_scale = 40.0
understeer_curve = SubResource("Curve_htvme")
understeer_curve_x_scale = 40.0
traction_recovery_speed = 20.0
collision_layer = 7
collision_mask = 3
mass = 1000.0
@ -45,9 +44,12 @@ custom_integrator = true
continuous_cd = true
max_contacts_reported = 128
contact_monitor = true
linear_damp_mode = 1
linear_damp = 0.5
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(-1, -1.36051e-08, -8.63576e-08, -2.87879e-08, 0.983969, 0.178338, 8.25469e-08, 0.178338, -0.983969, 4.58152e-07, 1.76689, -2.8478)
transform = Transform3D(-1, -2.02334e-08, -8.50491e-08, -2.87879e-08, 0.994803, 0.10182, 8.25469e-08, 0.10182, -0.994803, 4.6449e-07, 2.24116, -4.7912)
fov = 68.9128
[node name="Body" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.687824, 0.174572)

View file

@ -52,7 +52,7 @@ void CarPhysics::process_oversteer(double delta_time) {
float const target = this->current_steering == 0.f
? 0.f
: (this->evaluate_oversteer_curve(this->local_velocity.z) + (this->brake ? this->handbrake_oversteer : 0.f)) * Math::sign(this->current_steering);
if(Math::abs(target) >= Math::abs(this->current_oversteer) && Math::sign(target) == Math::sign(this->current_oversteer))
if(target != 0.f && Math::abs(target) >= Math::abs(this->current_oversteer) && Math::sign(target) == Math::sign(this->current_oversteer))
this->current_oversteer = target;
else
this->current_oversteer = Math::move_toward(this->current_oversteer, target, float(delta_time * this->traction_recovery_speed));
@ -77,15 +77,15 @@ void CarPhysics::_integrate_forces(PhysicsDirectBodyState3D *state) {
this->last_velocity = state->get_linear_velocity();
state->set_linear_velocity(
(this->is_grounded()
? (this->local_to_world_velocity() + Vector3{0, float(-9.8f * state->get_step()), 0})
? (this->local_to_world_velocity() + Vector3{0, -0.05f, 0})
: (this->get_linear_velocity() + Vector3{0, float(-9.8f * state->get_step()), 0})));
}
void CarPhysics::integrate_steering(PhysicsDirectBodyState3D *state) {
float target_x_velocity = 0.f;
if(this->local_velocity.z != 0.f) {
Vector3 const steering_angle_vel = this->get_global_basis().get_column(1) * (
this->current_steering * Math::sign(this->local_velocity.z + this->current_oversteer * this->oversteer_steering_speed));
Vector3 const steering_angle_vel = this->get_global_basis().get_column(1) *
(this->current_steering * Math::sign(this->local_velocity.z) + this->current_oversteer * this->oversteer_steering_speed);
state->set_angular_velocity(steering_angle_vel * (1.0f-this->current_understeer));
target_x_velocity = this->current_steering * this->steering_inward_speed;
} else {
@ -104,17 +104,12 @@ void CarPhysics::integrate_engine_acceleration(PhysicsDirectBodyState3D *state)
this->local_velocity.z = 0.f;
}
this->local_velocity.z = Math::move_toward(
this->local_velocity.z,
this->get_true_target_speed(),
float(this->get_current_acceleration() * state->get_step()));
this->local_velocity.z = Math::move_toward(this->local_velocity.z, this->get_true_target_speed(), float(this->get_current_acceleration() * state->get_step()));
}
void CarPhysics::integrate_oversteer(PhysicsDirectBodyState3D *state) {
this->local_velocity.x = Math::clamp(
this->local_velocity.x - this->local_velocity.z * this->current_oversteer * this->slide_speed_acceleration,
-this->max_slide_speed,
this->max_slide_speed);
this->local_velocity.x = Math::clamp(this->local_velocity.x - this->local_velocity.z * this->current_oversteer * this->slide_speed_acceleration,
-this->max_slide_speed, this->max_slide_speed);
}
void CarPhysics::on_body_shape_entered(RID body_rid, Node *body, int body_shape_index, int local_shape_index) {

View file

@ -93,7 +93,7 @@ private:
float engine_brake_force{30.f};
float handbrake_force{40.f};
float handbrake_oversteer{1.f};
float traction_recovery_speed{100.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};

View file

@ -25,7 +25,7 @@ private:
const float max_speed{40.f};
const float max_speed_reverse{10.f};
const float steering_factor{2.f};
const float steering_factor{0.7f};
};
};