Follow path after interaction

Godot Version 4.1


Hi. I’ve a player node and a bunch of interactable objects. I’m trying to do something along these lines:
interact with object_1 → follow Path_1;
object_2 → Path_2 and so on.
Any suggestions? The follow Path_X in particular I have no clue what to do. Thanks.

Can you let us know what you mean by “Follow Path_X”? Do you mean a literal path in the game, or a path in a story? Is it a 2D game or a 3D game? Are you using Godot 3.X or 4.X?

for Path I mean a Path3D. The version is Godot 4.1.

Okay! I would use a combination of signals and PathFollow3Ds.

Step 1 - Add a PathFollow3D to each of your paths and a RemoteTransform3D to that. Set the remote_path to the node you want to move in your scene.

Step 2 - Create either a tween, animation or function to have the PathFollow3D move from the start point to the end point. As the RemoteTransform3D is a child of it, it should also move the object you want to move.

Step 3 - In your interactable code, add a signal to say the object has been interacted with. like - signal object_interacted_with
Once you’ve done that, whereever it recieves the interaction, have it emit this signal.

Step 4 - Connect the signal to your level scene and have it play the animation or tween of the relevant object!

If you want to make it more general, you could make a function that will create the animation and then connect the signal from the object and bind it.

The function:

func start_node_following_path(pathfollow: PathFollow3D):
	var tween = create_tween()
	tween = tween_property(pathfollow, "progress_ratio", 1, 5)

The connection:

var called_func = start_node_following_path.bind(pathfollow)

Everything is clear up untill step 3 and 4.

In your interactable code, add a signal to say the object has been interacted with.

You mean, in the interactable object script? Also the object has an interacted(body: var) that triggers an animation when interacted.

have it emit a signal

I imagine by connecting it to something, or to itself?

Connect the signal to your level scene

You mean the main parent node?

and have it play the animation or tween of the relevant object!


I’ve followed your instruction as much as I’ve could and the player node goes for the Path as soon as the simulation starts.

  1. I’ve created the RemoteTransform3D as a child of PathFollow3D
  2. set the remote path from RemoteTransform3D Ispector to player
  3. created a tween function within the PathFollow3D script sheet
  4. typed signal object_interacted_with in the object script sheet
  5. and that’s about it for what I’ve understood.

Yes, you’ve done that, good job!

Once you have a signal, you can emit it by writing interacted_with.emit() in your interacted function. You don’t need to connect it until the next step.

Yes, but as you’ve created script in the PathFollow3D, you could connect the signal directly to the path. If you click on the object you want to connect, on the tab in the top right, click on “node” then “signals” and you should see the signals you want to use. Right click on the object_interacted_with signal then “connect” and connect it to the pathFollow3D you want to use. You can click on “Pick” in the window that pops up and click on your tween method.

I didn’t realise you wanted the PLAYER to go along the 3D path, the reason why your player is going to that node straight away is because it starts replacing the players transformation straight away. Set the different update properties in the RemoteTransform3D to false, and add change the tween method to this:

func start_node_following_path():
	var tween = create_tween()
	tween = tween_property(self, "progress_ratio", 1, 5)
	$RemoteTransform3D.update_position = true
	$RemoteTransform3D.update_rotation = true

	#This keeps the player attatched until the tween finishes
	await tween.finished
	$RemoteTransform3D.update_position = false
	$RemoteTransform3D.update_rotation = false   

Give it a try, if you get stuck, let me know!

func _on_object_interacted(body):
	var tween = create_tween()
	tween = tween_property(self, "progress_ratio", 1, 5)
	$RemoteTransform3D.update_position = true
	$RemoteTransform3D.update_rotation = true
	$RemoteTransform3D.update_position = false
	$RemoteTransform3D.update_rotation = false

I’ve updated the tween (which is located in the PathFollow3D) and now is giving me this error:
Parse Error: Function “tween_property()” not found in base self.

Sorry, it should be tween.tween_property!

SO. APPARENTLY. I’ve managed to make things work out. Although within your answer there were some typos, which for someone like me who can’t digest coding as much, make things more confusing. But I’ve thoroughly appreciated your support since you’re the only one who gave me an answer.

Right click on the object_interacted_with signal

it’s object_interact_with

and you don’t need in the tweening script.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.