bullets now dont stand inmovile when their target is killed
authorEduardo <[email protected]>
Thu, 9 May 2024 11:48:20 +0000 (13:48 +0200)
committerEduardo <[email protected]>
Thu, 9 May 2024 11:48:20 +0000 (13:48 +0200)
components/base_bullet/BaseBullet.tscn
components/base_bullet/base_bullet.gd

index ec8907a0a5680439ba07ae865e80222efd52c56f..6f689d6657907a2e5eafe26cf43941d82f1d7b65 100644 (file)
@@ -5,7 +5,7 @@
 [sub_resource type="CircleShape2D" id="CircleShape2D_b7ejx"]
 radius = 4.96679
 
-[node name="BaseBullet" type="CharacterBody2D"]
+[node name="BaseBullet" type="Area2D"]
 script = ExtResource("1_0faoa")
 
 [node name="Polygon2D" type="Polygon2D" parent="."]
@@ -13,11 +13,9 @@ scale = Vector2(1.79425, 1.69033)
 color = Color(0.828474, 0.826652, 1.54018e-06, 1)
 polygon = PackedVector2Array(2.53263, -1.21713, 2.07215, -1.94741, 1.15119, -2.67769, 0, -2.92112, -1.15119, -2.67769, -2, -2, -2.53263, -1.21713, -2.76287, 0, -2.53263, 1.21713, -2.07215, 1.94741, -1.15119, 2.67769, 0, 2.92112, 1.15119, 2.67769, 2, 2, 2.53263, 1.21713, 2.76287, 0)
 
-[node name="Area2D" type="Area2D" parent="."]
-
-[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
+[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
 light_mask = 2
 scale = Vector2(1.00669, 1.00809)
 shape = SubResource("CircleShape2D_b7ejx")
 
-[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
+[connection signal="body_entered" from="." to="." method="_on_body_entered"]
index 5cfbb64fb0339dc9caf94f89564bc8be4a5dd383..bd83b3181415754b40d8bda52eaeb651bac272ad 100644 (file)
@@ -1,8 +1,9 @@
-extends CharacterBody2D
+extends Area2D
 
 @export var SPEED = 200.0
 var origin: Node2D
 var target: Node2D
+var last_angle_position: float
 
 
 func _ready():
@@ -10,10 +11,11 @@ func _ready():
                position = origin.position
 
 
-func _process(_delta):
+func _process(delta):
        if target:
-               velocity = position.direction_to(target.position) * SPEED
-               move_and_slide()
+               last_angle_position = position.angle_to_point(target.position)
+
+       position += Vector2(1, 0).rotated(last_angle_position) * SPEED * delta
 
 
 func set_origin(node: Node2D):
@@ -25,7 +27,7 @@ func set_target(node: Node2D):
        target = node
 
 
-func _on_area_2d_body_entered(body: Node2D):
+func _on_body_entered(body: Node2D):
        # if it is an enemy do some damage
        if body.name.to_lower().contains("enemy"):
                body.take_damage(1)