Locking Camera to Spline Path

Ok, so I’m trying to lock the player’s camera to a path for an on rails shooter. I’ve been trying to get this figured out for a while but still can’t get the camera to lock to the spline path that I’ve created in my scene. I’m trying to set it up where the player’s camera locks to the spline path when play begins. I thought this would do it, but it’s still not working.

I think you need to do this in every tick to make the camera stick to the spline.

I’ve tried replacing the being play event with a tick and it still just spawns the player at the current camera position.

When I said you need to do it at every tick, I meant you need to adavance through your Spline and update to a new location.
This should get you started:

I’ve already tried that tutorial and couldn’t get it to work. I’m wondering if it’s because the tutorial is based on the sidescroller project, while mine is a flying game?

@m2the1
Ok, I will give you a general idea how you could proecede.

Setup the spline path like it is explained in that tutorial. Now what you want to do is, when you move your charcter (ie when keys are pressed), instead of actually moving the character, you want to advance through the spline. ie, Imagine the spline is like a graph. Usually in a graph, you advance through the X-axis, and for each X-value, there is a Y-value right? So what we need here is when the movement key is pressed, we want to move forward in x-axis, get the y-value for this x-value and move the character to this y-value. So when you press the key, you will move forward in the spline, get the world-location of that spline point and move your character to that point.

However if you character and camera need to follow different paths (ie character moves normally, but camera follows a path), in such a case, you move your character normally but set the world-location ofr the camera component separately using the spline.

See if you can get this to work. Let me know if you need further help.

I’ll give it a shot and get back to you. The camera and the player’s ship will be locked to the same path. Actually, it’s the camera itself I’m trying to lock to the spline and the player’s ship is a child of the camera, but will be controlled by the player’s input. So the forward movement will be preset, but the player will control the movement of the ship within the boundaries of the camera’s view. Think something like StarFox or the space battles in Knights of the Old Republic.

I didn’t test this but you could use matinee to make the camera follow a spline with animation. But if you are making a cover shooter on rails in witch your moves the camera when on rails. You could make the camera when entering a scene animate to the central point and then animate pan to left or right if character takes cover left or right. Meaning you would make a spline path with all the camera positions and if you need the camera from point 1->4 you would skip 1->2, 2->3 and 3->4 and translate/transform the camera movement from point 1 to point 4 with some kind of value of time it takes for a transition.

I was using matinee at first, but after 4.3 came out with the spline tool, I decided that would be a better fit. And it’s not a cover shooter, so I wouldn’t really need all of that. I just need to get the camera to lock to the spline and have the player control the movement of the ship on the x and y axis.

Did you find how to do this?

If your game is always on the rails and moving, then you can just animate the camera using matinee, give the player control, don’t do letter box, etc… Because you always know where the player is.

If your game is not always moving, and the position of the player will dictate the position of the camera along the spline, then this is super complex, involving either calculus and/or linear algebra formulas to plot the closest point on the spline to the player. It’s a job that’s best left to an experienced programmer. (I’m trying to figure this out too and I’m attempting to hack something together)