I am trying to move a Area2d from right to left. It moves to the right, has a collision en go's to the left. This works.
But it needs to stop at is original position en move to the right again.
i got this so far, but having problems with .position? of global_position? Can anyone point me in the right direction? This is just for learning excersizes.
extends Area2D
var speed = 100
var moveBack = false
var startPos
var colPos
func _ready():
startPos = get_global_position() #get original starting position
print(startPos)
func _process(delta):
var velocity = Vector2.ZERO
colPos = $CollisionShape2D.global_position #gets colshape position
print(colPos) # the current position of the shape
if moveBack == false:
velocity.x += 1 # move to the right
if moveBack == true:
velocity.x -= 1 # move to the left
if colPos == startPos:
print('yehaa') # check of working
moveBack == false # move to the right
position += (velocity * speed) * delta
func _on_Player_body_entered(body):
""" works """
print('o no it hit me in the guts') # hits a collisionshape
moveBack = true