Looking quickly at the code, I think I know what the issue is. You are calling tween.start
every _process
call whenever bMoving
is true, rather than once when bMoving
is true, so the tween is constantly being restarted and only moving a single _process
call forward before being restarted again.
Using an additional boolean to detect if the tween has been started should fix the issue:
var did_tween_start = false
func Operation (Op, Next):
lastOp = currOp
currOp = Op
nextOp = Next
print ("Robot.Operation: ", lastOp, ", ", currOp, ", ", nextOp)
if (lastOp == Enums.OperationCard.EMPTY):
if (currOp == Enums.OperationCard.M1):
start = position
destination = position + Vector2(0,-32)
print ("position = ", position, ", ", destination)
print ("Start: ", start.y, "destination.y: ", destination.y)
$Sprite.play("Forward")
bMoving = true
did_tween_start = false
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
travel = (destination - start)*delta/32 # 32 pixels over 10 seconds
if (bMoving):
time += delta
print (", delta: ", delta, " = time: ", time, " -> position", position)
if (did_tween_start == false):
$Tween.interpolate_property(self, "position", start, destination, 10.0, \
Tween.TRANS_ELASTIC, Tween.EASE_IN)
$Tween.start()
did_tween_start = true
else:
time = 0.0