katana damage, no friendly fire
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
extends Area2D
|
||||
|
||||
@export var speed = 70
|
||||
@export var damage = 1
|
||||
@export var knockback_strength = 0.5
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
var direction = Vector2.RIGHT.rotated(self.rotation)
|
||||
self.position += direction * speed * delta
|
||||
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
if self.get_parent().is_in_group("Virus"):
|
||||
# Prevent friendly fire
|
||||
@@ -14,12 +16,14 @@ func _on_area_entered(area: Area2D) -> void:
|
||||
print_debug("Cursor bullet hit %s" % area.name)
|
||||
var area_parent = area.get_parent()
|
||||
if (area_parent.is_in_group("Virus")):
|
||||
area_parent.take_hit(1, self.position.direction_to(area.position) * 200, 1)
|
||||
area_parent.take_hit(damage, self.position.direction_to(area.position) * 200, knockback_strength)
|
||||
self.queue_free()
|
||||
|
||||
func _on_body_entered(body):
|
||||
if self.get_parent() == body:
|
||||
return
|
||||
print_debug("Cursor bullet hit %s" % body.name)
|
||||
body.take_hit(1, self.position.direction_to(body.position) * 200, 1)
|
||||
body.take_hit(damage, self.position.direction_to(body.position) * 200, knockback_strength)
|
||||
self.queue_free()
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
|
||||
@@ -1 +1,18 @@
|
||||
extends Node2D
|
||||
|
||||
@export var damage = 5
|
||||
@export var knockback_strength = 3
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
if self.get_parent().is_in_group("Virus"):
|
||||
# Prevent friendly fire
|
||||
return
|
||||
var area_parent = area.get_parent()
|
||||
if (area_parent.is_in_group("Virus")):
|
||||
area_parent.take_hit(damage, self.position.direction_to(area.position) * 200, knockback_strength)
|
||||
|
||||
func _on_body_entered(body):
|
||||
if self.get_parent() == body:
|
||||
return
|
||||
print_debug("Cursor bullet hit %s" % body.name)
|
||||
body.take_hit(damage, self.position.direction_to(body.position) * 200, knockback_strength)
|
||||
@@ -89,3 +89,6 @@ autoplay = "default"
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
|
||||
position = Vector2(1, 1)
|
||||
shape = SubResource("RectangleShape2D_b0k4l")
|
||||
|
||||
[connection signal="area_entered" from="Area2D" to="." method="_on_area_entered"]
|
||||
[connection signal="body_entered" from="Area2D" to="." method="_on_body_entered"]
|
||||
|
||||
Reference in New Issue
Block a user