Node2d disapears when using move_local_x

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

I have an object that I am trying to move along the x position relative to the player’s x position.

var laserPosition = Vector2()

laserPosition.x = playerPosition.x


The object disappears only when the move_local_x is in the code. Commenting it out makes the object reappear.

Any ideas why that is?

Try printing the position to see where it goes or checking the position in the runtime debugger.

exuin | 2021-09-05 00:16

yeah, I did this later and found that the object moving really fast off camera.
This is the code I used to fix it

var laserPosition = Vector2()

# Get player position
var playerPosition = get_parent().get_node("Player").position

# Laser position will equal player's position on X axis
laserPosition.x = playerPosition.x

position.x = laserPosition.x

15erixman | 2021-09-05 21:08