From 5d8b312dbdb0fb044ba1e428646e9765424549e8 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 11 Dec 2024 22:42:07 +0100 Subject: [PATCH] feat: aiming now has zoom effect --- src/player.cpp | 3 +++ src/player.hpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/player.cpp b/src/player.cpp index 608c8fb..4ccaf26 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1,6 +1,7 @@ #include "player.hpp" #include "utils/godot_macros.hpp" #include +#include #include void Player::_bind_methods() { @@ -23,6 +24,7 @@ void Player::_ready() { // setup camera this->camera_parent = this->get_node("%CameraParent"); this->camera_parent->set_global_rotation(this->get_global_rotation()); + this->camera = gd::Object::cast_to(this->get_viewport()->get_camera_3d()); } void Player::_process(double delta) { @@ -42,6 +44,7 @@ void Player::_process(double delta) { + (this->is_on_floor() ? gd::Vector3{} : gd::Vector3{0.f, -0.05f, 0.f}) // add some gravity if required }; this->set_velocity(motion / delta); // velocity has to be in m/s, root motion is framerate-dependent. meters/second=distance/time. + this->camera->push_zoom_effect(this->anim_tree->match_tags(PlayerAnimTree::Tags::Aim) ? .7f : 1.f, 100.f); } void Player::_physics_process(double delta [[maybe_unused]]) { diff --git a/src/player.hpp b/src/player.hpp index 03abeec..5536493 100644 --- a/src/player.hpp +++ b/src/player.hpp @@ -1,6 +1,7 @@ #ifndef TR_PLAYER_HPP #define TR_PLAYER_HPP +#include "camera_effects.hpp" #include "damageable_entity.hpp" #include "player_anim_tree.hpp" #include "utils/player_input.hpp" @@ -29,6 +30,7 @@ public: private: PlayerAnimTree *anim_tree{nullptr}; gd::Node3D *camera_parent{nullptr}; + CameraEffects *camera{}; utils::PlayerInput *input{nullptr}; gd::Node3D *model_node{nullptr}; gd::Vector2 input_directions{0.f, 0.f};