Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | NPC______ |
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 health_var = 20
var point_value = 100
var direction = 1
var velocity = Vector2()
var fire = false
signal instance_node(node, location)
func _physics_process(_delta):
if Global.score >= 3:
$Attack.start() <----- does not work
velocity.y = speed * direction
move_and_slide(velocity)
if is_on_wall():
direction = direction * -1
if health_var <= 0:
Global.play_sound(“Explosion”)
queue_free()
Global.score += point_value
emit_signal(“instance_node”, complete, global_position)
func _on_hurt_timeout():
$AnimatedSprite.play(“stance”)
func _on_hitbox_area_entered(area):
if area.is_in_group(“Enemy_Damager”):
health_var -= 1
Global.play_sound(“hit”)
area.queue_free()
$AnimatedSprite.play(“hurt”)
$hurt.start()
if area.is_in_group(“Secret”):
health_var -= 2
$AnimatedSprite.play(“hurt”)
$hurt.start()
Global.play_sound(“hit”)
if area.is_in_group(“Flash”):
health_var -= 5
Global.play_sound(“hit”)
if area.is_in_group(“Power”):
health_var -= 3
Global.play_sound(“hit”)
area.queue_free()
$AnimatedSprite.play(“hurt”)
$hurt.start()
func _on_Attack_timeout():
emit_signal(“instance_node”, attack1, $Position2D.global_position)
Game’s code
extends Node2D
func _ready():
Global.game = self
func _exit_tree():
Global.game = null
func _on_create_particles_enemy(particles, location):
var particles_instance = particles.instance()
add_child(particles_instance)
particles_instance.global_position = location
func instance_node(node, location):
var node_instance = node.instance()
add_child(node_instance)
node_instance.global_position = location