how to get backward?

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

how to make go backward ? i want to make my object go to the left it move more than 1200px and to the right if less than 0px.

if global_position.x > 1200:
    global_position.x -= 10
elif global_position.x < 0:
    global_position.x += 10
else:
    global_position.x += 10
:bust_in_silhouette: Reply From: njamster

Close enough:

var direction = Vector2.RIGHT

func _physics_process(delta):
    global_position += direction * 10

    if global_position.x > 1200:
        direction = Vector2.LEFT
    elif global_position.x < 0:
        direction = Vector2.RIGHT