I want to make an enemy stop walking and shoot a bullet every 5 seconds. Here is my current enemy code:
extends KinematicBody2D
const BULLET = preload("res://bullet.tscn")
const GRAVITY = 10
const SPEED = 50
const UP = Vector2.UP
var velocity = Vector2()
var direction = 1
func physicsprocess(delta):
velocity.x = SPEED * direction
if direction == 1:
$AnimatedSprite.flip_h = false
else:
$AnimatedSprite.flip_h = true
$AnimatedSprite.play("walk")
velocity.y += GRAVITY
velocity = move_and_slide(velocity, UP)
if is_on_wall():
direction = direction * -1
$RayCast2D.position.x *= -1
if $RayCast2D.is_colliding() == false:
direction *= -1
$RayCast2D.position.x *= -1
func onTimertimeout():
var bullet = BULLET.instance()
getparent().addchild(bullet)
bullet.position = $Position2D.globalposition