I'm working on getting the enemies to stop patrolling for a moment here and there. I ran into a problem but I have no idea how to fix it. My google fu has not revealed any answers I've tried reading the docs but I do not understand what is all going on honestly but I figured out and fixed a couple issues. I did add a timer node to the enemy, not sure if that helped or not.
extends KinematicBody2D
const GRAVITY = 30
const SPEED = 30
var velocity = Vector2()
var direction =-1
var timer = null
var patrol = true
func _ready():
timer = Timer.new()
timer.connect("PatrolTime", self, "change_patrol")
timer.one_shot = true
add_child(timer)
timer.start()
func _physics_process(delta):
print(timer) #was trying to see what timer would say
if is_on_wall():
direction = direction * -1
if patrol == false:
#change animation to idle (future)
else:
velocity.x = SPEED * direction
velocity.y = GRAVITY
velocity = move_and_slide(velocity, Vector2.UP)
func change_patrol():
patrol = !patrol
if patrol == true:
timer.set_wait_time(8)
else:
timer.set_wait_time(2)
timer.start()