Movement along looping spline
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?
asked Mar 14 '16 at 03:47 AM in Using UE4
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 :)
answered Mar 31 '17 at 04:13 PM
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.
answered Mar 14 '16 at 05:08 AM
Yes it stops at the end of the spline.
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;
Character Blueprint - http://imgur.com/5xxa0cJ
Spline Blueprint - http://imgur.com/oDbPC1R
Spline Path - http://imgur.com/GogIyhA
All I want is my character to run in circles when I hold left or right on the analog stick.
Follow this question
Once you sign in you will be able to subscribe for any updates here