Godot Version
4.3
Question
I’m trying to make a custom property for my Gun
node that I can change the delay between shots, how am I able to do that?
gun.gd
extends CharacterBody2D
@export var player : Node2D
@export var distance_from_player : float = 100
@export var bullet_scene : PackedScene
func _ready():
position = player.position + Vector2(distance_from_player, 0)
func _process(_delta):
var direction = (get_global_mouse_position() - player.position).normalized()
position = player.position + direction * distance_from_player
look_at(get_global_mouse_position())
if Input.is_action_just_pressed("mouse_left"):
print("Mouse Click Detected!")
shoot_bullet(direction)
func shoot_bullet(direction: Vector2):
print("Executing shoot_bullet()")
print(bullet_scene)
if bullet_scene:
print("Spawning Bullet!")
var bullet = bullet_scene.instantiate()
bullet.position = position
bullet.direction = direction
get_parent().add_child(bullet)
else:
print("Error: Bullet scene is not assigned!")