How do I move a pawn along a spline?

Hi there,

I’ve been really struggling with this for a while, so any help would be hugely appreciated! I’m trying to figure out how to move a Pawn along a spline component. This should be simple - all I want is a set path - but I can’t seem to figure it out or find any help with it. My pawn is the player character, which might be making it harder.

Thanks in advance!
Joseph

Thanks for the quick reply! I don’t seem to have a character movement component as I’m using a pawn instead of a character (due to the fact that the player controls a camera inside the pawn instead of the pawn itself, hence the need for movement via spline). Is there another way to do this? Thanks again

Okay thanks - I’m just a tad confused: How should the timer be set up? And how is the pawn communicating with the Spline BP? Thanks!

Hey there, try setting the character movement component to flying and on tick increment a timer variabled with the delta seconds, after that just access the spline and get the location and rotation at that time and use SetActorLocationAndRotation for the player with those values.

The same thing should apply except the character movement component part.

Okay, sorry to be a noob but how do I create a timer? I’ve used them before but not like this… also is this inside the pawn blueprint? Thanks again

On tick you have a Delta Seconds parameter, just keep adding that on the timer variable and that will keep track of how long it has passed. You can call get player pawn at index 0 and that should give you a reference to the pawn. After that just do what i said.

Hi, I created a quick project where this is showcased. You can find it here.

I can give more information about how this works but hopefully that will be enough :slight_smile:

Cheers!

It’s just a float variable that is the sum of all delta times. On the spline you can ask what is the location and rotation at the given time, you supply the timer variable and he’ll tell you what values to set the pawn.

Open up the testmap and have a look!

Instead of using a timer I have used a timeline inside the pawn to move it. If you open the timeline you can set the length of the track to control how long it is going to take the pawn to move across the spline.

The reference to the BP_Spline is being made through a variable that is being set in the level itself

226625-spline1.jpg

Then if you click on the Pawn in the level you can set the reference there:

Then you take the reference to the BP_Spline, you get the actual spline inside the blueprint and you get the spline length. Multiply this by the float from the timeline (which is going from 1 → 0) and you will have a gradual progress across the splines length. Hook this value up to the Get Transform at Distance Along Spline and use that to move your pawn during the update (tick) of timeline

That should be enough to understand everything :slight_smile: Hope it helped!

Cheers once again

The picture below shows how i did it for a basic path. In my case i was also making sure the static mesh faced along the spline and moved forward at a constant rate.
also in my example by changing the movement speed variable it would make the movement along the spline faster.

55 mins, hope it helps

Narg

Just to add further why a timeline is to prefer here.

1: You can reverse it to move the character in both directions over the spline.
2: The timeline can be altered to make the character move at different speeds over the spline (go quicker in the beginning, slow down in middle, speed up at end again)
3: It does not clutter down the tick, which is something you always want to aim for.

Thank you so much! After a bit of tinkering this works perfectly! And I was looking for something that would allow me to change speed at certain points, so this is hugely helpful! I can’t thank you enough! :smiley:

Thank you so much everyone for your responses! I’ve gone for the use of a timeline, but glad there are so many methods to this to suit different needs I/others may have in the future! :smiley:

Thanks a lot for all your help - this has taught me something so thank you!

Im glad it helped :slight_smile:
Please mark my answer as answered so that more people can find it in the future :slight_smile:

I realize this is an old thread but I thought I’d share my video anyway:
Unreal Engine 4 - Easy Character Spline Movement (Blueprints) + Gravity is unaffected :D - YouTube (14 mins)

Just in case there are others like myself who want to figure this out while keeping things simple.

Thank you for this - extremely helpful!

This tutorial was great, and just what I was looking for in understanding how it all works