I completed the above tutorial and have it working. But what I want is to have that same movement along a spline in a loop. I found the option “Closed Loop” in the details of the spline component within the spline blueprint. When activated it looks as if it should work, see picture.
http://imgur.com/xCZMDa0 - This should make it clear what I am trying to do, I want him to run forward along the spline when I hold right (counter-clockwise in the image) and the other way with left. It all works except for the looping part.
But there is no difference with “Closed Loop” checked or unchecked. The player character stops in the same place every time. What I am trying to get is for him to run in a circuit along this spline when I hold left or right.
Is “Closed Loop” not working or am I using it wrongly?
As with the tutorial, what did you do with the “Distance along spline” to loop? Also, what do you mean player character stop in the same place every time? Did it happen at the end of the spline, when you are about to loop the entire spline again?
You didn’t give out enough informations, so i can only guess that it has something to do the variable which you used to store “Distance along the spline”, after the first loop, you didn’t reset it’s value back to 0 and keep letting it grow, while your spline’s max distance doesn’t change, so your spline keep clamping your input variable to the maximum spline distance, thus setting your character at the same place.
I suggest that after you increase your "Distance along the spline " variable, add a branch, if that variable’s value is bigger than the maximum spline distance, set that variable’s value back to 0. Vice versa if you want to go backward, but this time check for value that go below 0 and set it’s value back to maximum spline distance.
I think your suggestion is what I need to do but i’m not sure how to do it. I do not know how to define what the max spline distance is for use in the < branch. I tried what you suggested but I can’t work it out. Below are some pictures I took which should communicate the problem better. I removed my attempt at your suggestion as I did not know how to do it. These are what I have now;
My suggestion is that you modify your MoveRight event, add the branch check right after you set your DistanceAlongSpline variable, and i think it will work out with your code pretty well.
Thanks a lot that did the trick. I worked out myself how to make him run in the oposite direction by adding the below piece. Thanks for taking the time to help me man.
I know this is an old thread but for anybody having the same issue, the modulo operator is what you’re looking for. If you do something like the picture I’ve attached, it should work smoothly in the loop
Modulo returns the remainder of input A over input B. That way, when your distance spills over (reach the end of the spline) it’ll seamlessly loop back to the beginning of the spline
Awesome, this works perfectly! Was trying to set the location based on time (get location at time), but the animation was always stuck at the end of the spline duration.