• Godot HelpProgramming
  • Simple Path follow 2D ( offset ) problem , I need sprite to pause/stop at certain points

I followed a YouTube tutorial I found to make a sprite follow a 2D path. It worked! To make the sprite "move" along the path I use a " _process(delta)" function to change its offset over time. What I need to do now is STOP the movement ( altering of offset) , when it hits certain points along the path. When the sprite stops it will change its animation. Below is how I have it planned out.

  1. sprite starts along path ( its animation is "walking")
  2. sprite stops at certain point ( for example when unit_offset = 0.7742 , sprite stops moving)
  3. when sprite stops moving it plays a new animation ("Actiontwo")
  4. when animation is done it resumes moving

I have an idea on how I will get the movement to stop ( probably with an if statement) but for some reason I can't access offset itself ( even though I have before), and I also can't get my new animation to play ( which is probably because of the offset issue). Below is my code:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

extends PathFollow2D


export var runSpeed = 210

func _process(delta):
	
	#makes sprite move on path 
	set_offset(get_offset() + runSpeed * delta)
	
	if get_unit_offset() == 0.7742:
		$AnimatedSprite.animation("Actiontwo")
		print_debug("cats")

	#delete sprite when it leaves to new room
	if (loop == false and get_unit_offset() ==1):
		queue_free()

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

The if statement "get_unit_offset() == 0.7742" was my attempt to change the animation. The rest of this code I inserted from a tutorial. Any ideas would be much appreciated!

4 days later

[KINDA SOLVED] I just decided to use an animation player & tree, it works better for my project.

2 years later