Cannot instance a preloaded scene

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

Hello, newbie user here.

I’m trying to get my character to shoot from alternating positions (i.e the first projectile fires from the left while the second from the right) and the code seemed to be mostly working.

However, the projectile isn’t instanced. It just doesn’t appear. No errors are given.

extends Area2D

var cooldownReady = true
var alternatingFire = 'left'
onready var projectile = preload("res://scenes/Player/Fire/allyProjectile.tscn")

func _ready():	
func _process(delta):
	if Input.is_action_pressed("ui_select") and cooldownReady == true:
	elif Input.is_action_pressed("ui_select"):
		print("On cooldown")

func fireGun(direction):
	cooldownReady = false
	var firedProjectile = projectile.instance()
	if direction == 'left':
		firedProjectile.position = $LeftGun.position
		alternatingFire = 'right'
		print("Now firing from the right")
	elif direction == 'right':
		firedProjectile.position = $RightGun.position
		alternatingFire = 'left'
		print("Now firing from the left")
func _on_CooldownTimer_timeout():
	cooldownReady = true
	print("Cooldown ready")

Here is the projectile in case there’s something wrong with it

extends Area2D

var velocity = Vector2(0, -1500)
var screensize

func _ready():
	screensize = get_viewport_rect().size
	print("I am created")

func _process(delta):
	position += velocity * delta
	if position.y < - 50:

func _on_allyProjectile_body_entered(body):
	if body.is_in_group("enemyBody") or body.is_in_group("terrainBody"):
:bust_in_silhouette: Reply From: Zappo_II

Just to add my 2 cents…

You might consider decreasing your projectile’s vertical speed, to check if it’s not just too damn fast leaving the screen…???

This is what may be happening.
At 1500 pixels per seconds the projectile is probably far past Y -50 on the first frame.

eons | 2018-11-25 13:25