I’m trying to get an NPC vehicle (advanced vehicle) to follow a spline BP. I hae seen a couple of tutorials on moving a character along a spline…but that’s just not working for the vehicle. In one case, I got the car to move, but not the wheels. In another, using the Vehicle Blueprint, I get errors saying to use teleport instead of set actor location.
Is there an easy method I’m just missing where I can place my vehicle and assign the spline to it and have it move along the spline (without paying for a plugin)?
Thanks,
-Tearl
You need to “drive” the car using the gas/brake/steer inputs of the vehicle controller. Typically, this is done through “rabbit chasing.”
To generate those inputs, you need to pick a point on the spline, somewhat ahead of the vehicle.
Now, calculate whether that point is on the left or right side of the vehicle. Apply turning in the appropriate direction.
Also, apply some gas to make it go. You may want to apply more gas if the point is straight ahead, and less gas for more turning.
Keep moving the point you’re chasing forward along the splne so it’s always a certain distance ahead. Tuning how far ahead you look is important – start with maybe 1000 units (10 meters) and go up or down from there based on need and desire.
Got it! That does the trick. I vary the speed based on how far the car is from the “rabbit” Close, it matches, further, it goes faster in order to catch up. This works well for when I nudge the NPC Vehicle off course:)
jwatte,
I’ve got this working…kind of. My only real issue is speed matching the rabbit. I have a rather weak solution. My vehicles get to where they start to “slinky” a lot until they crash. In other words, they get farther behind, so they speed up to catch up, but get too close…then slow down too much, then end up overshooting the rabbit. So, any advice on controlling the speed to maintain the distance better?