feat: implemented destructible objects and damage
This commit is contained in:
parent
5263fbad23
commit
21139369d4
10 changed files with 152 additions and 8 deletions
|
|
@ -80,7 +80,12 @@ void PlayerRunState::process(double delta) {
|
|||
switch_state<PlayerIdleState>();
|
||||
} else {
|
||||
double angle{ get_body()->get_basis().get_column(2).signed_angle_to(get_body()->get_transformed_movement_input(), { 0.f, 1.f, 0.f }) };
|
||||
get_body()->rotate_y(angle * delta * 5.f);
|
||||
double motion{ angle * delta * this->rotation_speed };
|
||||
if (Math::abs(motion) < Math::abs(angle)) {
|
||||
get_body()->rotate_y(motion);
|
||||
} else {
|
||||
get_body()->look_at(get_body()->get_global_position() - get_body()->get_transformed_movement_input());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,12 @@ protected:
|
|||
void unhandled_input(Ref<InputEvent> const &what) override;
|
||||
void state_entered() override;
|
||||
void state_exited() override;
|
||||
|
||||
private:
|
||||
float rotation_speed{ 10.f };
|
||||
|
||||
public:
|
||||
GET_SET_FNS(float, rotation_speed);
|
||||
};
|
||||
|
||||
class PlayerBasicAttackState : public PlayerState {
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -1,4 +1,6 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://ct650octef6l3"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://ct650octef6l3"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cwc5pk8n2n85j" path="res://objects/effects/destroyed_object.tscn" id="1_370rb"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_j8sr1"]
|
||||
size = Vector3(2, 1, 0.958)
|
||||
|
|
@ -6,8 +8,14 @@ size = Vector3(2, 1, 0.958)
|
|||
[sub_resource type="GDScript" id="GDScript_j8sr1"]
|
||||
script/source = "extends HitBox
|
||||
|
||||
func damaged(level: int) -> void:
|
||||
$\"..\".queue_free()
|
||||
@export var effect : PackedScene
|
||||
|
||||
func damaged(_level: int) -> void:
|
||||
var instance : Node3D = effect.instantiate()
|
||||
instance.position = global_position
|
||||
instance.rotation = global_rotation
|
||||
get_tree().current_scene.add_child(instance)
|
||||
owner.queue_free()
|
||||
"
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_j8sr1"]
|
||||
|
|
@ -22,6 +30,7 @@ mesh = SubResource("BoxMesh_j8sr1")
|
|||
[node name="HitBox" type="HitBox" parent="."]
|
||||
collision_layer = 3
|
||||
script = SubResource("GDScript_j8sr1")
|
||||
effect = ExtResource("1_370rb")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="HitBox"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.489746, 0)
|
||||
|
|
|
|||
88
project/objects/effects/destroyed_object.tscn
Normal file
88
project/objects/effects/destroyed_object.tscn
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://cwc5pk8n2n85j"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://tdwettjsx1o2" path="res://objects/effects/impact_flash_green_large.tscn" id="1_8gyt8"]
|
||||
[ext_resource type="PackedScene" uid="uid://cbdm6154y7m5k" path="res://objects/effects/dustcloud.tscn" id="2_tel7y"]
|
||||
[ext_resource type="PackedScene" uid="uid://ubl5uvtkrfso" path="res://objects/effects/object_piece.tscn" id="3_tel7y"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_v3jse"]
|
||||
script/source = "extends Node3D
|
||||
|
||||
func _ready():
|
||||
freeze_frame.call_deferred()
|
||||
$ImpactFlash2.restart()
|
||||
|
||||
func freeze_frame():
|
||||
Engine.time_scale = 0.00001
|
||||
var col : Color = get_world_3d().environment.ambient_light_color
|
||||
get_world_3d().environment.ambient_light_color = $DustCloud.process_material.color
|
||||
await get_tree().create_timer(0.1, true, false, true).timeout
|
||||
Engine.time_scale = 1.
|
||||
get_world_3d().environment.ambient_light_color = col
|
||||
$DustCloud.restart()
|
||||
"
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_v3jse"]
|
||||
size = Vector3(0.966, 0.2, 0.592)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_v3jse"]
|
||||
size = Vector3(0.959, 0.2, 0.576172)
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_tel7y"]
|
||||
size = Vector3(0.2, 0.2, 0.2)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_tel7y"]
|
||||
size = Vector3(0.2, 0.2, 0.2)
|
||||
|
||||
[node name="DestroyedObject" type="Node3D"]
|
||||
script = SubResource("GDScript_v3jse")
|
||||
|
||||
[node name="ImpactFlash2" parent="." instance=ExtResource("1_8gyt8")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.171534, 0)
|
||||
|
||||
[node name="DustCloud" parent="." instance=ExtResource("2_tel7y")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.312999, 0)
|
||||
|
||||
[node name="DestroyedObject" parent="." instance=ExtResource("3_tel7y")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0482381, 0.839077, 0.00899826)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DestroyedObject"]
|
||||
mesh = SubResource("BoxMesh_v3jse")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="DestroyedObject"]
|
||||
shape = SubResource("BoxShape3D_v3jse")
|
||||
|
||||
[node name="DestroyedObject2" parent="." instance=ExtResource("3_tel7y")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.951393, 0.616416, 0)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DestroyedObject2"]
|
||||
mesh = SubResource("BoxMesh_tel7y")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="DestroyedObject2"]
|
||||
shape = SubResource("BoxShape3D_tel7y")
|
||||
|
||||
[node name="DestroyedObject3" parent="." instance=ExtResource("3_tel7y")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.415327, 0.616416, 0.552001)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DestroyedObject3"]
|
||||
mesh = SubResource("BoxMesh_tel7y")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="DestroyedObject3"]
|
||||
shape = SubResource("BoxShape3D_tel7y")
|
||||
|
||||
[node name="DestroyedObject4" parent="." instance=ExtResource("3_tel7y")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.204972, 0.726766, -0.380615)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DestroyedObject4"]
|
||||
mesh = SubResource("BoxMesh_tel7y")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="DestroyedObject4"]
|
||||
shape = SubResource("BoxShape3D_tel7y")
|
||||
|
||||
[node name="DestroyedObject5" parent="." instance=ExtResource("3_tel7y")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.746109, 0.198163, -0.778075)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="DestroyedObject5"]
|
||||
mesh = SubResource("BoxMesh_tel7y")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="DestroyedObject5"]
|
||||
shape = SubResource("BoxShape3D_tel7y")
|
||||
|
|
@ -81,7 +81,7 @@ lower_fade = 1e-05
|
|||
cull_mask = 1048570
|
||||
|
||||
[node name="ImpactFlash2" parent="." instance=ExtResource("6_dvja1")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.20194, 0.251618)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.960885, 0.251618)
|
||||
draw_pass_1 = SubResource("QuadMesh_dvja1")
|
||||
|
||||
[node name="DustCloud" parent="." instance=ExtResource("4_p1nm6")]
|
||||
|
|
|
|||
15
project/objects/effects/object_piece.tscn
Normal file
15
project/objects/effects/object_piece.tscn
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://ubl5uvtkrfso"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_8gyt8"]
|
||||
script/source = "extends RigidBody3D
|
||||
|
||||
func _ready():
|
||||
angular_velocity = Vector3(randf(), randf(), randf())
|
||||
linear_velocity = position * 10
|
||||
await sleeping_state_changed
|
||||
set_deferred(\"process_mode\", Node.PROCESS_MODE_DISABLED)
|
||||
"
|
||||
|
||||
[node name="DestroyedObject" type="RigidBody3D"]
|
||||
collision_layer = 0
|
||||
script = SubResource("GDScript_8gyt8")
|
||||
|
|
@ -84,7 +84,7 @@ transitions = ["Start", "idle", SubResource("AnimationNodeStateMachineTransition
|
|||
graph_offset = Vector2(-228.371, 13.6511)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_1p07c"]
|
||||
size = Vector3(0.674805, 0.325928, 0.495117)
|
||||
size = Vector3(0.674805, 1.01257, 0.948242)
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_yaurm"]
|
||||
script/source = "extends Node3D
|
||||
|
|
@ -148,7 +148,7 @@ monitoring = false
|
|||
monitorable = false
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="character/character/Skeleton3D/BoneAttachment3D/DamageBox"]
|
||||
transform = Transform3D(1, -1.10539e-07, -3.35273e-08, 1.10539e-07, 1, 7.16536e-08, 3.35273e-08, -7.16536e-08, 1, -3.00942e-07, 0.147256, -0.0270206)
|
||||
transform = Transform3D(1, -1.19209e-07, -5.88596e-07, 4.76837e-07, 1, 4.24683e-07, -2.16067e-07, -7.45058e-08, 1, 0, -0.196067, -0.0270205)
|
||||
shape = SubResource("BoxShape3D_1p07c")
|
||||
|
||||
[node name="GroundCracksEmitter" type="Node3D" parent="."]
|
||||
|
|
|
|||
|
|
@ -56,4 +56,25 @@ transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -6.794
|
|||
size = Vector3(4.86313, 0.842651, 4.90196)
|
||||
|
||||
[node name="Table" parent="." instance=ExtResource("2_paw1w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.18104, 0.0109616, 5.68015)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.539985, 0.0109616, 4.10204)
|
||||
|
||||
[node name="Table2" parent="." instance=ExtResource("2_paw1w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.539985, 0.0109616, 2.06498)
|
||||
|
||||
[node name="Table3" parent="." instance=ExtResource("2_paw1w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.539985, 0.0109616, 0.207431)
|
||||
|
||||
[node name="Table6" parent="." instance=ExtResource("2_paw1w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.539985, 0.0109616, -1.79257)
|
||||
|
||||
[node name="Table7" parent="." instance=ExtResource("2_paw1w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.539985, 0.0109616, -3.79257)
|
||||
|
||||
[node name="Table4" parent="." instance=ExtResource("2_paw1w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.46001, 0.0109616, -0.395865)
|
||||
|
||||
[node name="Table8" parent="." instance=ExtResource("2_paw1w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.46001, 0.0109616, -2.39586)
|
||||
|
||||
[node name="Table5" parent="." instance=ExtResource("2_paw1w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.46001, 0.0109616, 1.58982)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue