I have a maze-like game with enemies moving in a grid based on the player's position on the grid. Enemies can be in a "moving" state where they continue in the same direction or a "not moving" state where, for one frame, they ask for their next direction and then begin moving that way.
An "Instructor" script generates the next direction for each enemy independently of the script that moves each enemy. However, when the "Instructor" runs there is a noticeable lag in the game. Ideally, this script would run over the course of several frames in the "moving" state. Is there a way I can tell Godot to make this script a low-priority and not interfere with the game physics?
Enemy
extends KinematicBody2D
func _ready():
set_fixed_process(true)
func _fixed_process(delta):
if is_moving:
# keep moving
if not is_moving:
# get directions from instructor
Instructor
extends Node2D
func _ready():
# starts a timer
func _on_Timer_timeout():
# calculate next direction for each enemy that needs one
I'm very new to game development, and while I've been able to find answers to most things online, I can't figure this one out. Thanks!