generated from Persson-dev/Godot-Xmake
shooting pens (locally)
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <godot_cpp/classes/input.hpp>
|
||||
#include <godot_cpp/classes/input_event_mouse_motion.hpp>
|
||||
#include <godot_cpp/classes/input_map.hpp>
|
||||
#include <godot_cpp/classes/packed_scene.hpp>
|
||||
#include <godot_cpp/classes/resource_loader.hpp>
|
||||
#include <godot_cpp/core/math.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
@@ -37,6 +39,8 @@ static constexpr float MAX_FOV_VELOCITY = SPRINT_SPEED * 2.0f;
|
||||
static const float LerpValue = 0.10;
|
||||
static const float AnimationBlend = 7.0;
|
||||
|
||||
static const char BulletScenePath[] = "res://Scenes/Weapons/pen.tscn";
|
||||
|
||||
void FirstPersonPlayer::_bind_methods() {}
|
||||
|
||||
FirstPersonPlayer::FirstPersonPlayer() : Player(), m_BobTime(0) {}
|
||||
@@ -102,6 +106,24 @@ void FirstPersonPlayer::_physics_process(float a_Delta) {
|
||||
m_Player->move_and_slide();
|
||||
|
||||
UpdateAnimation(a_Delta);
|
||||
|
||||
Shoot();
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::Shoot() {
|
||||
if (Input::get_singleton()->is_action_pressed("shoot")) {
|
||||
Ref<PackedScene> bulletScene = ResourceLoader::get_singleton()->load(BulletScenePath);
|
||||
auto* bullet = Object::cast_to<Node3D>(bulletScene->instantiate());
|
||||
|
||||
bullet->set_position(m_Camera->get_global_position());
|
||||
|
||||
Transform3D rotation = bullet->get_transform();
|
||||
rotation.basis = m_Camera->get_global_transform().basis;
|
||||
bullet->set_transform(rotation);
|
||||
|
||||
Node* entities = get_node<Node>("../../Entities");
|
||||
entities->add_child(bullet);
|
||||
}
|
||||
}
|
||||
|
||||
void FirstPersonPlayer::UpdateBobbing(float a_Delta) {
|
||||
|
||||
Reference in New Issue
Block a user