Godot Version
v4.2.2
Question
@export var path : Array[Vector2] = []
var nextNodeIndex : int = 1
@onready var lastNode : Vector2 = path[0]
@onready var nextNode : Vector2 = path[1]
func _process(delta):
if self.position == nextNode:
var srtMidEnd : int = 0 #start:-1 , mid:0, end:1
if nextNodeIndex == 0:
srtMidEnd = -1
if nextNodeIndex == path.size()-1:
srtMidEnd = 1
if srtMidEnd == 1:
print("test1")
nextNodeIndex = 1
lastNode = path[0]
nextNode = path[1]
self.position = lastNode
print(lastNode)
print(nextNode)
print(self.position)
else:
nextNodeIndex += 1
lastNode = nextNode
nextNode = path[nextNodeIndex]
self.position = self.position.move_toward(nextNode, moveSpeed * delta)
This code is trying to make a platform move along a path then at the end go back to the start and do it again. the platform is moving as it should however when it reaches the end it doesn’t work properly.
The line with self.position = lastNode doesn’t seem to be working, the platform does move towards the 2nd node (as it should) but it doesn’t set its position to the 1st node.
ive added output from prints as an attachment.
not sure what is happening here. thanks for any help!