Godot Version
4.1.1
Question
Hi y’all! I’m working on a game that aims to imitate this one: https://www.youtube.com/watch?v=TjRXYJ5ZUPM
however I am having a hard time getting my enemy objects to move slower, 21.05.2024_20.28.35_REC
I this is the main moving function:
func moveState(event = null):
await get_tree().create_timer(1).timeout
if curr_move > 0:
for dir in inputs.keys():
if get_direction_move() == dir:
curr_move -= 1
move_character(dir)
if followers.size() < max_size:
add_follower()
update_followers()
update_move_options()
else:
switch_state(States.ATTACK)
which is called in the _process
function
My idea was to use await but I’ve not had much luck. Any tips/ ideas on how to get this functionality to work correct? Let me know if there is further clarification needed! Thanks!
If you call moveState
in _process
it will still be called every frame. It will delay the execution of moveState
by one second, but that won’t be noticeable anymore one second after the game has been started, because from that point onwards there will always be a (delayed) call of moveState
finishing each frame!
So what you have to change is the actual call frequency of moveState
!
const THRESHOLD := 1.0
var time := 0.0
func _process(delta: float) -> void:
time += delta
if time == THRESHOLD:
moveState()
time = 0.0
(Remove the await
line from MoveState
for this to work properly) Alternatively, you could set up a Timer
and connect its timeout
signal to the moveState
function.
Thanks that put me in the right direction! Sadly it still didn’t work but I did find a solution that worked for me, not sure if its the right move but it works for now and I’m happy with it!
func _process(delta):
if turnState == 1:
match current_state:
States.MOVE:
time += int(delta*100)
moveState(time)
States.ATTACK:
attState()
States.END:
clear_old_markers()
turnState = 0
func moveState(time):
if (int(time)% 15 == 0):
if curr_move > 0:
for dir in inputs.keys():
if get_direction_move() == dir:
print(curr_move)
curr_move -= 1
move_character(dir)
if followers.size() < max_size:
add_follower()
update_followers()
update_move_options()
else:
switch_state(States.ATTACK)