Multiplying once in a if statement

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

Hello everyone, im new to programing and im struggling with my game.
I want to double the speed of an enemy, when the player is incide an area.
This is what I have.

  • gdscript
    func _on_Fov_body_entered(body: Node) -> void: velocity.x *= 2

If I do this it will keep multiplying as long as the player is incide the area.
How can i double the speed once but when i leave the area the speed(velocity.x) is back to normal.

:bust_in_silhouette: Reply From: kidscancode

Connect the body_exited signal and reduce the velocity in that function.

Thank you very much that worked amazingly.

Gabi | 2020-04-13 21:08