Shoot a fireball

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MightyRat

Hi, first of all I’m sorry I’m asking so many questions, I will re-pay when I’ll be more expert and able to aswer some questions myself (or supporting the engine on patreon). I want to make my player to shoot fireballs.

My fireball script:

    extends Area2D

const SPEED = 2
var velocity = Vector2()

func _ready():
	pass
	
func _physics_process(delta):
	velocity.x = SPEED + delta
	translate(velocity)
	$AnimatedSprite.play("shoot")


func _on_VisibilityNotifier2D_screen_exited():
	queue_free()

And I’ve added that to my player script:

const fireballl = preload("res://Fireballl.tscn")

if Input.is_action_just_pressed("ui_focus_next"):
		var fireball = fireballl.instance()   #ERROR HERE
		get_parent().add_child(fireball)
		fireball.position = $Position2D.global_position

Then I’ve added a “position 2d” to the player, so I could set the start position of the fireball from the player

The error is: " Invalid call. Nonexistent function ‘istance’ in base ‘PackedScene’ "

Shouldn’t velocity.x be “* delta” instead of “+ delta”?

SuperMatCat24 | 2023-02-25 18:05

:bust_in_silhouette: Reply From: jgodfrey

That should be instance() not istance() (note, you’re missing an n)

Thanks! I will add some info for who want to do the same, so this post won’t be that useless :confused:

MightyRat | 2020-05-16 15:52

:bust_in_silhouette: Reply From: Mohamed Hisham

fireballl constant that you made should be an onready variable like this

onready var fireballl = preload(“res://Fireballl.tscn”)