Tell any actor to animate along a spline using its default locomotion with this Actor Component.
https://dev.epicgames.com/community/learning/tutorials/ryL5/unreal-engine-follow-a-spline-and-report-distance-along-it-using-an-actor-component
Thank you , this is really helpfull and good learning for me!
Thanks !
One question: I tried this in ue4 but the static mesh does not change to another spline. Do you know how to fix that?
Kind regards,
Thanks !
Great tutorial. Really smart, really helpful and much appreciated!
On additional question: I’ve tried to build up a scene with a car driving on a landscape. As long as I stay on flat plane everything work pretty good. In that moment when I’m using a surface which is not flat, or which is for example rotated around x- axis or y- axis, the car is starting to “wave” around the spline. Do you have an idea how to fix this. This would be really a great help.
best regards
In my example, the mesh is seeking a position along the spline on every tick. The exact spline component that it is looking for is stored as a variable. You can easily modify this Blueprint to switch out that spline variable at any time based on your desired conditions, and it will start looking for the new spline.
Thanks for the kind words!
It’s true that I didn’t test the driving direction in extreme conditions. I built it assuming that the left and right steering controls would eventually guide it to the right spot, so I’m not sure what your terrain looks like if it’s “rotated around x-axis”. It’s totally possible that my math for finding the steering direction doesn’t work right if the world is closer to being upside down.
Any waviness that I saw, like quickly steering left and right, could be fixed by adjusting the Forward Aim Location. The farther in front of the object you put that focus point, the softer the steering and transitions will be, which should reduce the wiggles. You might also consider adjusting the turning radius and friction of your wheels, which will also affect the turning speed. Make sure you turn on the debug visuals to help figure it out.
In my “Proceed to Destination” function I do have a “Map Ranged Clamped Node” for converting the rotation angle of the destination into the 0-1 steering range. I clamped it at 120 degrees. You could play with that value as well.
Hi everyone. It’s been a couple months since I released the sample files and I wanted to inform you that I updated it to address an issue with this “waviness” or “wobble” on some splines. Specifically it’s been pointed out that on straight or subtle lines, the car goes back and forth and over-corrects itself. I have improved the math with one simple Power function to address this. Feel free to download the sample again or just modify this one piece of the ProceedToDestination function.
Hello, this spline system is really great! It’s almost perfect for what I need for my game. I only have two problems with it though and I would be glad if you could help me with it. For one, I have the component on my player, I don’t want them to be going towards the spline at all times. I just want them to hit the path and then follow the spline and once they’re done with the spline, then they get full movement back. I always don’t want the player to just move on the spline by itself. I want the player to be able to walk, run, jump, etc but just do it on the spline path. My game is a 2.5D game so I have the player planar movement constraints on which interferes with the spline component. I figure that I would have to get the spline component to turn off the players planar constraints and then reenable them when they’re out of the spline. Here’s an example of what I am trying to achieve here
I want the player to be able to walk, run, jump, etc but just do it on the spline path.
For simplicity’s sake my example has everything happening on Tick all the time. You would take this off of Tick in the component and instead access the various variables with your own custom input events on your character. When you tell your player to “Move” you feed it the location of the spline as the direction to move. If you rotate your player with input, the player can still look ahead of itself for the next place to jump.
If you do want to override player controls, you can use a Timeline or something to run all the other code in the component to move the player.
I’ll try that. Thanks!
Another question came in through my DMs.
Is there any option to increase the speed of the car. I tried to change the data type of the variable speed to integer but nothing seems changed & I tried max speed Cm/s also but the speed remains same.
The “cm/s” speed controls will only work on the static mesh or a basic actor in my example. That is for a situation in which we precisely control the translation every frame.
The “speed” variable is an overall multiplier I added so that once you set the maximum you can adjust it more finely as you wish. In the case of the car, its movement is controlled entirely through physics as part of the ChaosVehicleComponent. My Speed multiplier is only adjusting the Throttle input. If you want to make this car go faster you will need to modify its engine settings in its Blueprint, and you can also adjust settings in the wheels like friction. This can get pretty complicated and when I was making the example I definitely had some cases where the car would go too fast and overshoot the spline on tight corners. It’s all physics based!
Is there a way to take control of the spline animation via sequencer? Perhaps keyframe spline percentage? I looked at the chaos drive example where the car is pushed through take recorder. That is great for capturing dynamics on top of spline animation. If dynamics are not required and I want to keep the splines live for flexibility, can I directly control advancement along the spline via sequencer? Thanks!
This is an interesting idea. Unfortunately I can’t think of the right way to do this. The spline percentage in my example is more of a Get and not a Set. The only way to have it scrubbable is to use that Take Recorder trick you mentioned.
I can think of a gross workaround using a custom event in the Sequencer track to find a percentage point on the spline and set the actor transform there, but that’s something you’d have to key every frame potentially.
@.Phillips Thanks for this great component! I’m using it to drive physics vehicles, and its awesome. Currently if my vehicle collides with another object or vehicle it continues to try to follow the spline. I would like to add a function either to this component or to the vehicle, that disables throttle at the moment of a collision. What would be the best way to do this?
The component is setting the throttle every frame on the Tick event. You could add a boolean variable into the component like “HasCollided” and interrupt the flow with a Branch. In the vehicle BP you could make a new BeginOverlap event that then gets the SplineFollowComponent and flips that boolean on or sets its Speed to 0.
Very cool! Thanks for sharing, incredibly useful!
I have a similar question. I would love to be able to control a car using distance in the sequencer. A video I found very similar to yours shows this being done. Especially at the 3:00 mark. Is this possible with your setup? And if so what would I need to change to the blueprint?
Reference: UE4 Control Rig Update - YouTube
Thanks in advance! I’m fairly new to Unreal and am looking to replicate a car commercial using your method.
This is such a well built and explained tutorial - thank you! If you were to adjust the setup so that it drives a single controller inside a control rig down the spline, how would you do it?
I’m not a control rig user, but this looks like a different system than my example. I am telling the actor to check where it is supposed to go every frame, and that’s in game on the Tick function. This way of rigging it where you can define an arbitrary point on the spline and have it update in sequencer is a little outside my understanding. To get something similar with my system you would use Take Recorder to record the vehicle on the spline and then scrub the resulting animation in sequencer as you see fit.
Thanks for the reply ! This was super helpful. I