I have a Boss in my game who is supposed to bounce up and down the screen, activate after a specific score, and shoot a fireball after a timeout. Everything but the attack works. The attack works partially. This is because when I autostart the attack timer, it works no problem. But when I try and activate it in the code, it refuses to work. All of my signals are connected and don't know why it is not working.
Here's my code:
Note: any things that relate to the instance node is a signal connected to the game's code.
Edit: I found that when I have the timer (known as $Attack.start() ) in the code and have autostart on, the timer disables itself. I also thought maybe changing the name to just timer, as my attack had a similar name. But this had made no difference
Boss code
extends KinematicBody2D
var attack1 = preload("res://Characters/Enemies/Units/Blastboss.tscn")
var complete = preload("res://Misc/stage cleaner.tscn")
export (int) var speed = 30
var healthvar = 20
var pointvalue = 100
var direction = 1
var velocity = Vector2()
var fire = false
signal instance_node(node, location)
func physicsprocess(delta):
if Global.score >= 3:
$Attack.start() <----- does not work
velocity.y = speed * direction
moveandslide(velocity)
if isonwall():
direction = direction * -1
if healthvar <= 0:
Global.playsound("Explosion")
queuefree()
Global.score += pointvalue
emitsignal("instancenode", complete, globalposition)
func onhurt_timeout():
$AnimatedSprite.play("stance")
func onhitboxareaentered(area):
if area.isingroup("EnemyDamager"):
healthvar -= 1
Global.playsound("hit")
area.queuefree()
$AnimatedSprite.play("hurt")
$hurt.start()
if area.isingroup("Secret"):
healthvar -= 2
$AnimatedSprite.play("hurt")
$hurt.start()
Global.playsound("hit")
if area.isingroup("Flash"):
healthvar -= 5
Global.playsound("hit")
if area.isingroup("Power"):
healthvar -= 3
Global.playsound("hit")
area.queue_free()
$AnimatedSprite.play("hurt")
$hurt.start()
func onAttack_timeout():
emitsignal("instancenode", attack1, $Position2D.global_position)
Game's code
extends Node2D
func _ready():
Global.game = self
func exittree():
Global.game = null
func oncreateparticlesenemy(particles, location):
var particlesinstance = particles.instance()
addchild(particlesinstance)
particlesinstance.global_position = location
func instancenode(node, location):
var nodeinstance = node.instance()
addchild(nodeinstance)
nodeinstance.globalposition = location