Download

Mining-car movement along tracks. Your suggestion is needed (can you connect splines?)

Hello everyone!

The idea:
You build tracks by using different blueprints (one is straight, one is a curve etc) You can simply scroll threw them. This is fine and suits to the rest of the game.
A mining car gets spawned at the beginning of the track and travels along the whole track.

How I did it:
Every blueprint has a spline component included which dictates the movement
The car checks at certain points what he is currently overlapping with and chooses this spline to follow along.
It kinda works, but needs a lot of precise box collisions etc. Not very ideal…

How I wanted to do it but couldnt figure out how:
Each time you build a new track (remember, different blueprints) the included spline checks for already existing ones (tracks that have been build before) and connect the spline to one big spline that the car can follow more easily.
I dont know how to connect points, if this is even possible.

Do you guys have any idea how I could do this? Couldnt find any resource on this.
Or do you have a even better idea to solve this?

As always, thanks a lot you lovely people.

BR and stay healthy

In order to join the spline, you actually have to extend the existing one. Perfectly possible, probably a bit of a fiddle to code though…

EDIT: Now I’m thinking about it. Instead of having the splines on the track parts, why not have ‘spline point markers’ on them? You only ever have one spline in the game, and when the player adds track, that spline gets points added where the markers are.

I have been working on a vehicle traffic system using splines and I agree with above – have some sort of helper actor where you want each spline point and then generate one spline that builds itself along those points.

Then when a track piece is added or removed rebuild the entire spline again.

Hello you two!

Okay I tried building this already. A second Blueprint which just contains a spline component, which gets updated each time a traintrackBP is build.
It does work quite well already and the car follows along the new build track, already smoother than before :slight_smile:

But: I decided to work with splines initially to archive this nice curve effect that the train or actor can follow along.
I managed to add poins easily, but they are all “straight” I guess. How can I add points which the splines connect in a curve?

I know nothing about splines so your help is appreciated!

Thanks

When you make the spline point you want to then also set the type and tangent. Setting the type to “curve” usually does the trick but depending on what you need you have to do a bit more and set the tangents. Does that help? Let me know if you need more details.

Hello Bmiletta,

yes I need more of your help.
So I know that there is a function to set a point type called “Set Spline Point Type”. But I need to feed it a point index, which I will never know since the curve could be build anywhere within the track.
So what could I do?

I imagine the following:
Always: “Addd Spline Point” → Feed this to an array
When a curve is build: “Add Spline Point” → Feed to array → “Set Spline Point Type to Curve” and Point Index is always the last Index of the whole array.
If I call it immediately it should always be the last one, right… How do I get the “Spline Points” from my SplineComponent tho? Couldnt find anything.

Alternativley I imagine I can use “Get Spline Length”, which I assume is equal to last array index, and just feed this into the point index of “Set Spline Point Type”

What do you think?

EDIT: Okay just noticed spline length is not equal to the amount of spline points but the “actual distance” of the spline. Now I am lost :smiley:

EDIT 2: Alright alright, Spline Component -> GET NUMBER OF SPLINE POINTS (how could I not see this) -> +1 = Index of Set Spline Point Type

Works perfect!

Thanks for the hints :wink: