Fireball Projectile

Godot Version

4.2

Question

I wanted to add a Fireball as a projectile for my Metroidvania style game, I tried a lot of tutorials but nothing seems to work, I press the button to shoot the fireball but nothing happens. Can someone help me?

@onready var Fireball = preload("res://fireball.tscn")

func shoot():
  if Input.is_action_just_pressed("shoot"):
    var magic = Fireball.instantiate() as Node2D
    magic.global_position = muzzle.global_position    
    get_parent().add_child(magic)

Is the function shoot actually called from somewhere?

Add this to your script:

func _unhandled_input(event):
	if Input.is_action_just_pressed("shoot"):
		shoot()

And remove if Input.is_action_just_pressed("shoot"): line from the shoot function.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.