Compare commits

..

3 commits

5 changed files with 15 additions and 9 deletions

View file

@ -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<PlayerInput>(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;
}

View file

@ -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);

View file

@ -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() {

View file

@ -66,7 +66,7 @@ void PlayerInput::unhandled_input(Ref<InputEvent> const &event) {
}
Ref<InputEventMouseMotion> mouse_motion{ event };
if (mouse_motion.is_valid()) {
Vector2 state{ -mouse_motion->get_relative() * 0.001f };
Vector2 state{ -mouse_motion->get_relative() * 0.0005f };
emit_signal(sig_look_input, state);
}
if (event->is_action("primary_fire")) {

View file

@ -185,6 +185,8 @@ void Rifle::notify_deselected() {
if (HeadsUpDisplay * hud{ HeadsUpDisplay::get_singleton() }) {
hud->set_reticle_visibility(true);
}
this->in_alt_mode = false;
this->fov = 0.f;
}
void Rifle::reload_full() {