add hitting projectile function
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user