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 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
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 and use SetActorLocationAndRotation for the player with those values.
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.
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 , you supply the timer variable and he’ll tell you what values to set the pawn.
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
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
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.
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!
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!