diff --git a/modules/wave_survival/player_body.cpp b/modules/wave_survival/player_body.cpp index 59902322..b0953645 100644 --- a/modules/wave_survival/player_body.cpp +++ b/modules/wave_survival/player_body.cpp @@ -15,7 +15,6 @@ void PlayerBody::on_child_entered(Node *node) { node->connect("child_entered_tree", callable_mp(this, &self_type::on_child_entered)); if (PlayerInput * input{ cast_to(node) }) { input->connect(PlayerInput::sig_movement_input, callable_mp(this, &self_type::set_movement_input)); - input->connect(PlayerInput::sig_look_input, callable_mp(this, &self_type::on_look_input)); input->connect(PlayerInput::sig_jump, callable_mp(this, &self_type::on_jump_input)); input->connect(PlayerInput::sig_run, callable_mp(this, &self_type::on_run_input)); } @@ -32,7 +31,6 @@ void PlayerBody::on_child_entered(Node *node) { void PlayerBody::process(double delta) { GETSETM(this->camera, fov_factor, { - float const target_fov{ get_is_running() ? 1.2f : 1.0f }; fov_factor = Math::move_toward(fov_factor, target_fov, float(delta)); }); } @@ -46,7 +44,14 @@ void PlayerBody::physics_process(double delta) { } else { input *= this->walk_speed; } - velocity = velocity.move_toward(Vector3{ input.y * get_global_basis().get_column(2) + input.x * get_global_basis().get_column(0) } + Vector3{ 0.f, velocity.y, 0.f }, delta * this->acceleration); + Basis const basis{ this->camera->get_global_basis() }; + Vector3 forward{ -basis.get_column(2) }; + forward.y = 0.f; + forward.normalize(); + Vector3 left{ -basis.get_column(0) }; + left.y = 0.f; + left.normalize(); + velocity = velocity.move_toward(Vector3{ input.y * forward + input.x * left } + Vector3{ 0.f, velocity.y, 0.f }, delta * this->acceleration); velocity += get_gravity() * delta; }); move_and_slide(); @@ -56,10 +61,6 @@ void PlayerBody::set_movement_input(Vector2 state) { this->movement_input = state; } -void PlayerBody::on_look_input(Vector2 look) { - rotate_y(look.x); -} - void PlayerBody::on_jump_input() { if (this->is_on_floor()) { GETSET(velocity, { @@ -110,6 +111,9 @@ PackedStringArray PlayerBody::get_configuration_warnings() const { if (find_children("*", WeaponInventory::get_class_static()).is_empty()) { warnings.push_back("This node has no inventory and will cause crashes.\nConsider adding a WeaponInventory node as a child."); } + if (find_children("*", PlayerCamera::get_class_static()).is_empty()) { + warnings.push_back("This node has no camera of type PlayerCamera, expect crashes.\nConsider adding a PlayerCamera node as a child."); + } return warnings; } diff --git a/modules/wave_survival/player_body.h b/modules/wave_survival/player_body.h index 8369549c..00d06e0a 100644 --- a/modules/wave_survival/player_body.h +++ b/modules/wave_survival/player_body.h @@ -16,7 +16,6 @@ class PlayerBody : public CharacterBody3D { void physics_process(double delta); void set_movement_input(Vector2 state); - void on_look_input(Vector2 look); void on_jump_input(); void on_run_input(bool run); diff --git a/modules/wave_survival/player_camera.cpp b/modules/wave_survival/player_camera.cpp index 737f58a2..c4a42ef1 100644 --- a/modules/wave_survival/player_camera.cpp +++ b/modules/wave_survival/player_camera.cpp @@ -9,6 +9,7 @@ void PlayerCamera::on_look_input(Vector2 input) { GETSET(rotation, { rotation.x = CLAMP(rotation.x + input.y, -Math::PI / 2.0, Math::PI / 2.0); }); + global_rotate(Vector3{ 0.f, 1.f, 0.f }, input.x); } void PlayerCamera::update_fov() {