Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | fatcat__25 |
I have my game’s “clock” tied to the movement of a character being controlled by the player. It works by the player queuing a series of moves, which the code then iterates through. The basic code looks like this:
var path = [] #This contains the series of moves.
var destination #The final point in the path.
var animator = get_node_or_null("Path to a tween node")
signal time_advanced(time)
while player.position != destination:
var next_move = path.pop_back()
#Some code to determine the time taken in the next move.
emit_signal("time_advanced", time)
animator.interpolate_property(player, "position", null, next_move, ...)
animator.start()
#This is where I need to pause the code.
The time_advanced signal is connected to a piece of code in all of the NPCs’ code that handles movement for them. They each have their own path, and their own speed. As a result, they need to be able to move multiple times, each time the player moves. The code I have for this is roughly as follows:
var path = []
var time #This stores how much time this character has to act.
var destination
var animator = get_node_or_null("Path to a tween node")
func on_player_time_advanced(time):
#Code to determine cost of next move.
while time >= move_cost:
var next_move = path.pop_back()
time -= move_cost
animator.interpolate_property(self, "position", null, next_move, ...)
animator.start()
yield(animator, "tween_all_completed")
As you can see, the NPCs are able to move several spaces for one player move. This means that I cannot use the yield I do for them for the player, because the player has to wait for more than one round of tweens to complete. I am looking for a way to pause the code for the player. Any suggestions are appreciated.