Add functionality to automatically shoot bullets from gun
This commit is contained in:
parent
4689798b38
commit
5914260597
|
@ -7,6 +7,7 @@
|
|||
radius = 16.0
|
||||
|
||||
[node name="Bullet" type="Area2D"]
|
||||
top_level = true
|
||||
collision_layer = 0
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_6niae")
|
||||
|
|
12
gun.gd
12
gun.gd
|
@ -7,3 +7,15 @@ func _physics_process(delta):
|
|||
var target_enemy = enemies_in_range.front()
|
||||
#var target_enemy = enemies_in_range[0]
|
||||
look_at(target_enemy.global_position)
|
||||
|
||||
|
||||
func shoot():
|
||||
const BULLET = preload("res://bullet.tscn")
|
||||
var new_bullet = BULLET.instantiate()
|
||||
new_bullet.global_position = %ShootingPoint.global_position
|
||||
new_bullet.global_rotation = %ShootingPoint.global_rotation
|
||||
%ShootingPoint.add_child(new_bullet)
|
||||
|
||||
|
||||
func _on_timer_timeout():
|
||||
shoot()
|
||||
|
|
7
gun.tscn
7
gun.tscn
|
@ -21,4 +21,11 @@ position = Vector2(102, 0)
|
|||
texture = ExtResource("1_vcr1c")
|
||||
|
||||
[node name="ShootingPoint" type="Marker2D" parent="WeaponPivot/Pistol"]
|
||||
unique_name_in_owner = true
|
||||
position = Vector2(25, -11)
|
||||
|
||||
[node name="Timer" type="Timer" parent="."]
|
||||
wait_time = 0.3
|
||||
autostart = true
|
||||
|
||||
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]
|
||||
|
|
Loading…
Reference in New Issue