shooting pens (locally)

This commit is contained in:
2024-08-24 18:32:24 +02:00
parent b28fdc0a94
commit 8d12eff214
6 changed files with 53 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,19 @@
[gd_scene load_steps=3 format=3 uid="uid://c475s3klxqoej"]
[ext_resource type="ArrayMesh" path="res://Assets/Models/Weapons/pen_base.res" id="1_clcko"]
[ext_resource type="ArrayMesh" path="res://Assets/Models/Weapons/pen_lid.res" id="2_0u0nh"]
[node name="Stylo" type="Node3D"]
[node name="Armature" type="Node3D" parent="."]
transform = Transform3D(5, 0, 0, 0, 0.0178025, -4.99997, 0, 4.99997, 0.0178025, 0, 0, -0.0892955)
[node name="pen_base" type="MeshInstance3D" parent="Armature"]
transform = Transform3D(0.140708, 0, 0, 0, -1.67737e-08, 0.140708, 0, -0.140708, -1.67737e-08, -1.12406e-11, 0.00945318, -3.65384e-09)
mesh = ExtResource("1_clcko")
skeleton = NodePath("")
[node name="pen_lid" type="MeshInstance3D" parent="Armature/pen_base"]
transform = Transform3D(1.14449, 0, 0, 0, 1.14449, 0, 0, 0, 1.14449, 7.98797e-11, 5.07782e-10, -0.0671831)
mesh = ExtResource("2_0u0nh")
skeleton = NodePath("")

View File

@@ -57,3 +57,8 @@ escape={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
] ]
} }
shoot={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}

View File

@@ -28,6 +28,7 @@ class FirstPersonPlayer : public Player {
void UpdateFOV(float delta); void UpdateFOV(float delta);
void UpdateCamera(const godot::InputEventMouseMotion&); void UpdateCamera(const godot::InputEventMouseMotion&);
void UpdatePosition(float delta); void UpdatePosition(float delta);
void Shoot();
}; };
} // namespace blitz } // namespace blitz

View File

@@ -5,6 +5,8 @@
#include <godot_cpp/classes/input.hpp> #include <godot_cpp/classes/input.hpp>
#include <godot_cpp/classes/input_event_mouse_motion.hpp> #include <godot_cpp/classes/input_event_mouse_motion.hpp>
#include <godot_cpp/classes/input_map.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/core/math.hpp>
#include <godot_cpp/variant/utility_functions.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 LerpValue = 0.10;
static const float AnimationBlend = 7.0; static const float AnimationBlend = 7.0;
static const char BulletScenePath[] = "res://Scenes/Weapons/pen.tscn";
void FirstPersonPlayer::_bind_methods() {} void FirstPersonPlayer::_bind_methods() {}
FirstPersonPlayer::FirstPersonPlayer() : Player(), m_BobTime(0) {} FirstPersonPlayer::FirstPersonPlayer() : Player(), m_BobTime(0) {}
@@ -102,6 +106,24 @@ void FirstPersonPlayer::_physics_process(float a_Delta) {
m_Player->move_and_slide(); m_Player->move_and_slide();
UpdateAnimation(a_Delta); 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) { void FirstPersonPlayer::UpdateBobbing(float a_Delta) {