Compare commits
3 commits
7b3c2b5b6f
...
909e83e779
Author | SHA1 | Date | |
---|---|---|---|
![]() |
909e83e779 | ||
![]() |
dc65707ff1 | ||
![]() |
eea0d85ff7 |
|
@ -7,10 +7,24 @@ void PlayerCamera::_bind_methods() {
|
|||
}
|
||||
|
||||
void PlayerCamera::on_look_input(Vector2 input) {
|
||||
// PI / 2.1 to avoid change to the flattened forward vector
|
||||
static const double LOOK_LIM{ Math::PI / 2.1 };
|
||||
GETSET(rotation, {
|
||||
rotation.x = CLAMP(rotation.x + input.y, -Math::PI / 2.1, Math::PI / 2.1);
|
||||
rotation.x = CLAMP(rotation.x + input.y, -LOOK_LIM, LOOK_LIM);
|
||||
});
|
||||
global_rotate(Vector3{ 0.f, 1.f, 0.f }, input.x);
|
||||
lead_weapon(input * this->weapon_lead_speed);
|
||||
}
|
||||
|
||||
void PlayerCamera::lead_weapon(Vector2 movement) {
|
||||
this->weapon_lead_rotation.x += movement.y;
|
||||
this->weapon_lead_rotation.y += movement.x;
|
||||
this->weapon_lead_rotation = this->weapon_lead_rotation.normalized() * CLAMP(this->weapon_lead_rotation.length(), -this->weapon_lead_limit, this->weapon_lead_limit);
|
||||
for (Variant child : get_children()) {
|
||||
if (Node3D * child3d{ cast_to<Node3D>(child) }) {
|
||||
child3d->set_rotation(this->weapon_lead_rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerCamera::update_fov() {
|
||||
|
@ -20,7 +34,7 @@ void PlayerCamera::update_fov() {
|
|||
}
|
||||
|
||||
void PlayerCamera::update_offset() {
|
||||
bool const is_running{ this->body->get_is_running() };
|
||||
bool const is_running{ this->body->get_is_running() && this->body->is_on_floor() };
|
||||
if (is_running != this->was_running) {
|
||||
this->was_running = is_running;
|
||||
this->run_bob_time = 0.0;
|
||||
|
@ -28,8 +42,8 @@ void PlayerCamera::update_offset() {
|
|||
double wave{ Math::sin(this->run_bob_time) };
|
||||
Vector3 offset{ Vector3{ float(wave), float(Math::abs(wave)), 0 } * this->run_bob_amplitude };
|
||||
if (!is_running) {
|
||||
this->run_bob_time = MIN(this->run_bob_time, this->run_bob_amplitude);
|
||||
offset = offset.lerp(Vector3(), this->run_bob_time / this->run_bob_amplitude);
|
||||
this->run_bob_time = MIN(this->run_bob_time, this->run_bob_blend_out);
|
||||
offset = offset.lerp(Vector3(), this->run_bob_time / this->run_bob_blend_out);
|
||||
}
|
||||
GETSET(position, {
|
||||
Basis const basis{ get_basis() };
|
||||
|
@ -89,4 +103,5 @@ void PlayerCamera::recoil(float r) {
|
|||
GETSET(rotation, {
|
||||
rotation.x = CLAMP(rotation.x + r, -Math::PI / 2.0, Math::PI / 2.0);
|
||||
});
|
||||
lead_weapon({ 0, 0.02f });
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ class PlayerCamera : public Camera3D {
|
|||
GDCLASS(PlayerCamera, Camera3D);
|
||||
static void _bind_methods();
|
||||
void on_look_input(Vector2 input);
|
||||
void lead_weapon(Vector2 movement);
|
||||
void update_fov();
|
||||
void update_offset();
|
||||
void ready();
|
||||
|
@ -31,6 +32,10 @@ private:
|
|||
double run_bob_time{ 0.0 };
|
||||
double run_bob_amplitude{ 0.025 };
|
||||
double run_bob_frequency{ 10.0 };
|
||||
double run_bob_blend_out{ 0.2 };
|
||||
double weapon_lead_limit{ Math::PI * 0.0075 };
|
||||
double weapon_lead_speed{ 0.15 };
|
||||
Vector3 weapon_lead_rotation{ 0, 0, 0 };
|
||||
};
|
||||
|
||||
#endif // !PLAYER_CAMERA_H
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://dqo1pfy3r00ai"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://dc26l1ync7env" path="res://assets/gui/reticle.svg" id="1_1o2rr"]
|
||||
[gd_scene format=3 uid="uid://dqo1pfy3r00ai"]
|
||||
|
||||
[node name="HeadsUpDisplay" type="HeadsUpDisplay"]
|
||||
anchors_preset = 15
|
||||
|
@ -19,11 +17,6 @@ anchor_bottom = 1.0
|
|||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Reticle" type="TextureRect" parent="CenterContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
texture = ExtResource("1_1o2rr")
|
||||
|
||||
[node name="Control" type="Control" parent="CenterContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
|
|
|
@ -28,6 +28,9 @@ script = SubResource("GDScript_qot2n")
|
|||
[node name="Hitbox" parent="wretched/Character/Skeleton3D" index="2" node_paths=PackedStringArray("health")]
|
||||
health = NodePath("../../../../HealthStatus")
|
||||
|
||||
[node name="CollisionShape3D2" parent="wretched/Character/Skeleton3D/Hitbox" index="0"]
|
||||
transform = Transform3D(1, 6.8945504e-21, 0, 6.2038546e-25, 1.0000037, 0, 0, 0, 1.0000037, -2.2362435e-16, 0.35283393, -0.013339132)
|
||||
|
||||
[node name="Hitbox" parent="wretched/Character/Skeleton3D/SpineAttach" index="0" node_paths=PackedStringArray("health")]
|
||||
health = NodePath("../../../../../HealthStatus")
|
||||
|
||||
|
@ -35,6 +38,9 @@ health = NodePath("../../../../../HealthStatus")
|
|||
health = NodePath("../../../../../HealthStatus")
|
||||
damage_modifier = 4.0
|
||||
|
||||
[node name="CollisionShape3D" parent="wretched/Character/Skeleton3D/HeadAttach/Hitbox" index="0"]
|
||||
transform = Transform3D(1.0000024, -1.4661055e-09, 2.3283064e-09, 6.548362e-11, 0.9999224, 0.013243848, 4.0745363e-09, -0.013244033, 0.9999193, -4.656613e-10, 1.3035285, -0.014328403)
|
||||
|
||||
[node name="CollisionShape3D" parent="wretched/Character/Skeleton3D/BoneAttachment3D/DamageBox" index="0"]
|
||||
transform = Transform3D(1, -9.834766e-07, -2.454035e-06, 1.4305115e-06, 0.9999989, -8.145726e-06, 1.8983264e-06, 7.3344854e-06, 1, -0.20908, -5.9604645e-07, -4.7683716e-07)
|
||||
|
||||
|
|
Loading…
Reference in a new issue