1
Fork 0
mirror of https://github.com/RYGhub/the-cold-night.git synced 2024-11-26 06:24:18 +00:00
the-cold-night/src/entities/behaviours/BulletSpawn.gd

21 lines
604 B
GDScript3
Raw Normal View History

2022-04-03 00:53:56 +00:00
extends Node2D
export var bullet: PackedScene = preload("res://src/entities/Bullet.tscn")
export var bullet_container_node_path: String = "../.."
onready var bullet_container_node: Node = get_node(bullet_container_node_path)
onready var source: Node2D = get_parent()
2022-04-03 00:09:19 +00:00
func _process(_delta):
2022-04-03 00:53:56 +00:00
if Input.is_action_just_pressed("player_shoot"):
shoot()
2022-04-03 00:09:19 +00:00
2022-04-03 00:53:56 +00:00
func shoot():
2022-04-03 00:37:44 +00:00
var new_bullet = bullet.instance()
2022-04-03 00:53:56 +00:00
new_bullet.set_position(source.global_position)
bullet_container_node.add_child(new_bullet)
var rotation = new_bullet.get_angle_to(get_global_mouse_position())
new_bullet.set_rotation(rotation)