How to follow a spline

I’m currently developing a game that has elements similar to infinite runners or the 3D Sonic games. I have the track, the movement and items etc.

The game is fully functional and almost ready to ship, but I want to experiment with a new idea to make the levels feel more interesting. SO I played around with spline components so I can have the track warp and turn. I have achieved this with a construction script and setting the distance between spline points etc - but the real issues are as follows :

The character runs automatically down the X axis, which isn’t always in line with the track.

The items that are generated also no longer follow the track.

What I’m trying to achieve :

  • I want the character to follow the spline rather than just the X axis, but still allow the player to move left and right (Y axis) and jump.
  • Allow the generated pickups to adhere to the spline.

I’d really appreciate help with this.

Hi Kenomica,

Yes the Spline is excellent for creating rails. You have a few options at your disposal. You can get the Location, Rotation, and Direction along the spline using either Time or Distance. What you end up having to do on your end to utilize this is creating a variable which can hold your distance or time. Next you increment this value up in order to progress on the spline. The results are outputted by these nodes. You can also get tangents for more direction information.

23997-step1_spline.png

Now to setup what you want with these tools you must create

This was all made very loosely and should be taken as-is. I believe this should work. I’ve done it a few times, so I feel safe saying this should work. If you would like me to help you with your setup directly I can do that.

Thanks for the detailed reply! it’s a little complex, since I’ve never attempted something like this.

I’m glad my post made sense.

The main issue is that the movement system is controlled (currently) by using Add Input & uses the character’s movement speed, since it can be changed using things such as the difficulty level, boosts and obstacles which launch the player back as well as obstacles which slow the player down.

I obviously need to keep that as it’s an integral part of the system. There is also a character chasing the player which uses the same system.

Also, an even larger issue is making the spawned items adhere to the track.

I will certainly give this a go and experiment further. Thank you very much.

No problem at all Kenomica.

The system you currently have would work within this setup. You would just have to feed vector your characters input like how I have “Take Character / Actor & Apply Input”.

The way I build tracks at this point is in this order. Either a spline is placed or generated. Then I have a script which will place tracks on the spline. Next I have the obstacles, and etc spawn on the track on construction of that track. This way makes it easier to understand for me when I locally offset obstacles and etc to the track.

But I would love to see what you finally decide to on because I honestly haven’t found a way that has stole my heart. ;D

Apologies for the late reply - I have sadly decided to abandon using spline components, since the number of tracks cause a performance impact - So I’ve decided to stick with my straight tracks for now as I can use instances.

Not as nice to look at, but performs much better.

Thanks for tour help, all the same. :slight_smile: