Download

Camera moving on spline falls behind player

Hi again. This ones really getting to me.

I have a camera which is always pointing at the character and is set to move along a spline and the character moves.
The problem is that the camera doesn’t quite keep up with the character.
Check this video out and you’ll see what I mean. It also shows my blueprint set up. The only thing it doesn’t show is my spline blueprint which is just a standard spline shape.

I am almost certain it has something to do with the selected parts here:
3.PNG

Is there someway I can set a minimum and maximum distance that the camera can be from the capsule component?

Thanks muchly!

Well as far as I can tell there is no build-in method for accurately finding a closest point near a spline, so I’m guessing this is not very easy to pull off (could be heavy on math).

Another user has made a camera spline tutorial that might help though.
http://gregmladucky.com/blog/?p=445

ahh thanks for the reply dude! That’s the first guide I used but i couldn’t get it to work though it is exactly like what I need.
I ended up following this guide and modifying it. https://forums.unrealengine.com/showthread.php?24522-Tutorial-Blueprint-Spline-locked-sidescroller-%28e-g-Klonoa-Pandemonium-style-game
This tutorial moves the character based on the input axis forward then gets distance along spline, but my character moves right and left or diagonal which again lags the camera behind.
What I have so far is the best I’ve come up with so far.

Hmmmm I really don’t know what to try!

:frowning:

I’m thinking maybe I could draw another spline right along the floor and get the distance form the character to that spline and then set the position of the camera in relation to the character on it’s own spline.

I say this without having the slightest clue how I would go about doing this. :stuck_out_tongue:

You can’t; there’s no built-in functionality for projecting a world location onto a spline (I should know, I had to figure out the math for my spline-based grinding system and it involves getting the world location of all spline points in an array, finding the nearest two to a given location, finding the ratio of the distance from the location to each of those two, using that ratio to find the weighted average of the distance along the spline at each of those two points, then snapping the actor to the spline at that distance) and the math, as you can see, is intense enough that one would NOT want to be performing it every Tick, at least not using BPs.

There’s probably a cheaper way but it isn’t super easy; I can provide more details when I get back to my PC but essentially you would take your camera spline and use it to define, via construction script, a series of trigger volumes. These would each fire an event on overlap; what you would do is use a separate actor for your camera, but set it to have a planar constraint on its motion, and use these overlaps to adjust the normal of that constraint. With enough trigger volumes, you can essentiallt create a “curved plane” in space that the camera actor is bound to. Then you can use simpler movement commands to keep the camera following the player and let the planar constraint system ensure that the camera remains fixed to this track.

I use this system to temporarily snap the player to 2.5D planes which can curve through 3D space in my game and it works exceptionally well (and the framerate cost is very small, though the memory footprint may get larger as you can have hundreds and hundreds of these triggers being constructed for a given spline).

Beyond that there’s probably a smarter C++ way of doing this but I couldn’t tell you what that was…

Ahhh fair enough. That makes a lot of sense. I think i’ll have ago at your method my self but please when you get to your pc would you be able to provide me with something to reference and follow? I get the essence of what you’re telling me but implementing it I might find a little complicated. :stuck_out_tongue:

Although saying that, surely there’s a way of constraining the camera to the character and just have it follow back and forth along a spline?
Like maybe setting a distance between two components with a bit of leeway but have one of the components follow a path? Maybe I’m clutching at straws… I dunno. :stuck_out_tongue:

I’m making progress and learning and that’s just how it goes. (:

Thanks!