Godot Version
4
Question
Want to have a Player scene follow different paths, so I’m using remotetransform and updating it with code.
This button is in the game UI, when I press it, sends a signal which in turn triggers a function within the Player scene.
Example, the player is in a settlement, therefore he isn’t on a path, when I click the button which corresponds to a path, the argument passed goes to the current_location the player is at the moment, checks for the selected path, and passes this path as an argument:
func _on_button_s_pressed():
print(%Player.current_location.path_s)
%Player.follow_path(%Player.current_location.path_s)
Print shows that it finds the correct path:
Path_Abisia-Abou:<Path2D#30903633132>
The function starts by updating the player current location, and the location status, then it assigns the player to the remotetransform.remote_path of the path that was given.
func follow_path(path):
self.current_location = path
print(current_location)
self.location_status = "path"
print(location_status)
path.get_child(1).get_child(0).remote_path = self.get_path()
print(path.get_child(1).get_child(0).remote_path)
With print functions I know that the current_location is being updated correctly:
Path_Abisia-Abou:<Path2D#30903633132>
and that the player is correctly being assigned to the remotetransform:
/root/World/Player
So now with this updated data, still in the player scene, I have a _physics_process(): that moves the player accordingly, it asks if the player is currently on a path, and if he is it should move by updating the progress of the followpath2d node:
func _physics_process(delta):
while self.location_status == "path":
print(%Player.current_location.get_child(1))
%Player.current_location.get_child(1).progress += speed * delta
print(%Player.current_location.get_child(1).progress)
print(%Player.position)
By printing I know that its finding the pathfollow2d node:
Follow:<PathFollow2D#30937187566>
and progress is being updated correctly each frame, but player position remains always the same at each frame, and on the 2D view the Player scene doesn’t move aswell.
Help is appreciated, thank you.