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.
- sprite starts along path ( its animation is "walking")
- sprite stops at certain point ( for example when unit_offset = 0.7742 , sprite stops moving)
- when sprite stops moving it plays a new animation ("Actiontwo")
- 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!