stop a function from running

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zombie

i have the function the makes the enemy move and i have another function that makes the player able to kill the enemy . when the second function is running the enemy will still move 1 sec before he dissepears so i want to stop the first function :slight_smile:
help

You should add more context. Technically, if you are not using multiple threads, only 1 function can run at the same time, so I imagine you want the enemy to stop moving as soon as it’s killed.

The solution to your bug probably lies in you movement logic, where your still calling move_and_slide or some similar function even though the enemy is dead. Something like the following would be a good starting point to consider

var isAlive = true
func _physics_process():
    if isAlive:
        enemyMoveLogic()
func kill():
    isAlive=false
func enemyMoveLogic():
    #....
    pass

godot_dev_ | 2023-06-14 13:31