Ok so I would like someone to help me understand why my code isn't working and if they can give me an answer to fix it. So basically I'm new to coding and I would some to look at my code and tell me why the bullets are not spawning.
extends KinematicBody2D
var speed = 200
onready var obj = get_parent().get_node("Player")
onready var fireDelayTimer = $fireDelayTimer
export var fireDelay: float = 1
const bulletE1 = preload("res://EnemyBullet1.tscn")
func _physics_process(delta):
var dir = (obj.global_position - global_position).normalized()
move_and_collide(dir * speed * delta)
look_at(obj.position)
func firedelay():
if fireDelayTimer.is_stopped():
fireDelayTimer.start(fireDelay)
fire()
func fire():
var bullet = bulletE1.instance()
get_parent().add_child(bullet)
bullet.position = $Position2D.global_position
bullet.velocity = obj.position() - bullet.position
bullet.look_at(obj.position())
This is all the code for the enemy which I would like to get the bullets to spawn in. This is also the same code i use for the player just with a few tweaks, however only the player bullets work and not the enemy's. If someone could tell me why its not working that would be appreciated.