diff --git a/modules/going/player_states.cpp b/modules/going/player_states.cpp index 49d3422b..cd254baa 100644 --- a/modules/going/player_states.cpp +++ b/modules/going/player_states.cpp @@ -30,9 +30,10 @@ void StandingState::physics_process(double delta) { } PlayerState::StateID RunningState::get_next_state() const { + Vector3 const velocity{this->get_body()->get_velocity()}; if(!this->get_body()->is_on_floor()) { return FallingState::get_class_static(); - } else if(this->get_body()->get_velocity().is_zero_approx()) { + } else if(Vector2{velocity.x, velocity.z}.is_zero_approx()) { return StandingState::get_class_static(); } else if(Input::get_singleton()->is_action_just_pressed(PlayerBody::split_step_action) && this->get_body()->get_velocity().length() > this->get_body()->get_min_step_speed()) { return SplitStepState::get_class_static(); @@ -46,8 +47,8 @@ void RunningState::state_entered() { } void RunningState::process(double delta) { - if(!this->get_body()->get_velocity().is_zero_approx()) { - Vector3 const current{this->get_body()->get_velocity()}; + Vector3 const current{this->get_body()->get_velocity()}; + if(!current.is_zero_approx()) { Vector3 const cross{Vector3{0.f, 1.f, 0.f}.cross(current).normalized()}; Vector3 const desired_direction{this->get_body()->get_desired_direction()}; this->lean_modifier = Math::move_toward( @@ -55,8 +56,11 @@ void RunningState::process(double delta) { cross.dot(desired_direction) * this->get_body()->get_model_lean(), float(this->get_body()->get_model_lean_speed() * delta) ); - Vector3 up{Vector3{0.0, 1.0, 0.0} + cross * this->lean_modifier}; - this->get_body()->get_model()->look_at(this->get_body()->get_global_position() - current, up); + Vector3 const up{Vector3{0.0, 1.0, 0.0} + Vector3{cross.x, 0.f, cross.y} * this->lean_modifier}; + Vector3 const forward{current.x, 0.f, current.z}; + if(!forward.is_zero_approx()) { + this->get_body()->get_model()->look_at(this->get_body()->get_global_position() - current, up); + } } } @@ -75,7 +79,11 @@ void RunningState::physics_process(double delta) { } void RunningState::state_exited() { - this->get_body()->get_model()->look_at(this->get_body()->get_global_position() - this->get_body()->get_velocity()); + Vector3 const velocity{this->get_body()->get_velocity()}; + Vector3 const velocity_flat{velocity.x, 0.f, velocity.z}; + if(!velocity_flat.is_zero_approx()) { + this->get_body()->get_model()->look_at(this->get_body()->get_global_position() - velocity_flat); + } this->lean_modifier = 0.f; } diff --git a/project/objects/player.tscn b/project/objects/player.tscn index de52095d..5c10d775 100644 --- a/project/objects/player.tscn +++ b/project/objects/player.tscn @@ -9,7 +9,7 @@ height = 2.15448 [sub_resource type="GDScript" id="GDScript_eqqp1"] script/source = "extends Camera3D @export var dist : float = 2.0 -@export var pivot_height : float = 3.0 +@export var pivot_height : float = 1.0 @export var look_target_height : float = 1.0 func _ready(): @@ -23,8 +23,7 @@ func _process(_delta): [node name="Player" type="PlayerBody"] wall_min_slide_angle = 0.785398 -floor_max_angle = 0.968658 -floor_snap_length = 1.5 +floor_max_angle = 0.460767 [node name="PlayerStateMachine" type="PlayerStateMachine" parent="."] @@ -36,8 +35,8 @@ shape = SubResource("CapsuleShape3D_bxedw") transform = Transform3D(-1, -6.18173e-08, -6.18173e-08, -6.71313e-08, 0.99594, 0.0900246, 5.60012e-08, 0.0900246, -0.99594, 3.76484e-07, 1.43409, -2.96511) fov = 100.0 script = SubResource("GDScript_eqqp1") -dist = 1.5 -pivot_height = 2.5 +dist = 1.75 +pivot_height = 2.0 look_target_height = 1.5 [node name="character" parent="." instance=ExtResource("1_eqqp1")]