add hitting projectile function

This commit is contained in:
Teatov 2025-02-18 02:49:46 +10:00
parent cd7bc7a82f
commit 80b7881cc6
5 changed files with 25 additions and 11 deletions

View File

@ -21,9 +21,9 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("BoxMesh_860q6")
[node name="MeshInstance3D2" type="MeshInstance3D" parent="MeshInstance3D"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, -0.339801)
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.552548, -0.339801)
mesh = SubResource("CylinderMesh_esok8")
skeleton = NodePath("../..")
[node name="Marker3D" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.624811, -0.590804)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.036, -0.590804)

View File

@ -14,9 +14,9 @@ height = 1.8
[sub_resource type="BoxMesh" id="BoxMesh_fdktb"]
size = Vector3(0.5, 0.5, 0.5)
[sub_resource type="CylinderShape3D" id="CylinderShape3D_m8fdo"]
height = 1.0
radius = 1.5
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_5qjrf"]
radius = 2.0
height = 6.0
[node name="Player" type="CharacterBody3D"]
collision_layer = 16
@ -36,11 +36,11 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.17779, 0.357218)
mesh = SubResource("BoxMesh_fdktb")
[node name="AttackArea" type="Area3D" parent="."]
collision_layer = 0
collision_layer = 32
collision_mask = 32
script = ExtResource("3_8pbtx")
_collision_debug_material = ExtResource("4_ll2ct")
[node name="CollisionShape3D" type="CollisionShape3D" parent="AttackArea"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("CylinderShape3D_m8fdo")
shape = SubResource("CapsuleShape3D_5qjrf")

View File

@ -10,8 +10,8 @@ radius = 0.25
radius = 0.25
height = 0.5
[node name="Projectile" type="Area3D"]
top_level = true
[node name="Projectile" type="AnimatableBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.535, 0)
collision_layer = 32
collision_mask = 32
script = ExtResource("1_kv6x5")

View File

@ -12,6 +12,7 @@ func _ready() -> void:
_debug_collision_shapes.init(get_children(), self, _collision_debug_material)
Debugger.add_event("attacked")
attacked.connect(func() -> void: Debugger.event_emitted("attacked", []))
body_entered.connect(_on_body_entered)
func _unhandled_input(event: InputEvent) -> void:
@ -21,3 +22,12 @@ func _unhandled_input(event: InputEvent) -> void:
func _attack() -> void:
attacked.emit()
func _hit_projectile(projectile: Projectile) -> void:
projectile.queue_free()
func _on_body_entered(node: Node3D) -> void:
if node is Projectile:
_hit_projectile(node as Projectile)

View File

@ -1,5 +1,5 @@
class_name Projectile
extends Area3D
extends AnimatableBody3D
@export var _collision_debug_material: Material
@ -18,7 +18,7 @@ func _ready() -> void:
global_position = _start_position
func _process(delta: float) -> void:
func _physics_process(delta: float) -> void:
if _life_timer <= 0:
queue_free()
@ -30,3 +30,7 @@ func init(velocity: Vector3, start_position: Vector3, lifetime: float = 10) -> v
_velocity = velocity
_start_position = start_position
_lifetime = lifetime
func set_velocity(velocity: Vector3) -> void:
_velocity = velocity