Move NPC actor on spline

I am having an issue trying to move an NPC along a spline and be interrupted by the player. For example, if pawn sensing detects the player, then it should move on a positive direction on the spline. If the character moves in front of the NPC, then it should move in the opposite direction. The NPC is a Character Blueprint and I’m trying to use Simple Move to get it to move. Any insight?

Here’s how I did it for one of my games. Direction is a float either 1 or -1 depending on if it’s moving up or down the spline. I do some extra fancy stuff with Roll in my game you can probably ignore. I also RInterp the rotations which you might not need. I basically call this in the NPCs event tick passing in the delta time.

Set Sanitized Distance basically calls “Set Distance” but has a bunch of other messy stuff in there to deal with what happens on an open vs closed spline. How it should wrap around or just stop when it hits an open end.

“Set Distance” is just the setter for the distance variable. You need a variable to track how far along the spline it is.

Here is the part of my Event Tick that would call this. You will need your Input Events to raise/lower the speed variable. Those are super complicated in my game, so the BPs are really hairy.

Thanks! I’m trying it out now. My question is what is the Set Sanitized Distance? I think it’s causing an issue because my NPC only spins in circles if it’s false and does nothing if it’s true.

Ok. I still can’t seem to get my NPC to move along the spline though. It just rotates at the beginning. I don’t have a set distance node because I’m not sure how to calculate that along the spline.

Hi Furroy, if you have a closed spline, how do you make the character continue move, i tried set 0 to distance but it didn’t work?