Title is hopefully self explanatory. But I was wondering if anyone could give me pointers on how I would be able to get a first person character with animations to follow lets say a spline and still give me control over where they look along the body rotations. So imagine im following a spline but my upper body including hands and weapon are looking in a different direction based on a gizmo that is parented to the character. Would something like this be achievable?
Your first person char is just those arms and a weapon, but no lower body right? If that’s true, then here’s what you’ll need.
An actor blueprint with a spline component for the character to follow
A way for your character to get easy reference to that component inside the actor
A means to convert fwd input into a distance moved along the spline and a
function to physically move the character
A separate system for control rotation
For the spline, you can make an new Actor blueprint with a spline mesh component inside it. This will give you more freedom to make actions happen along the length or have it change shape etc etc down the road. That component will give you a short spline segment with two vertices and two bezier handles to start with. I’d leave the first vert alone so it stays at the origin, but the other vert you can move around to start making your path. Holding Alt and dragging will create additional verts, or you can click on the spline and add verts thru a popup. I wont go into more on spline creation - thats easy enough to search for. For now, just understand that you’ve got a blueprint container thats in the world, and inside that container is a component that is the actual spline.
Given how often your character is going to need to get information from this exterior component, it’s probably smart to create two variables: One of your new spline blueprint type (object ref) to store the container, and one of type Spline Component (object ref) to store the spline inside that container. To set these: If your character is placed on the map and gets possessed, then you can simply click the eyedropper by the container variable and choose the spline actor directly. But if you’re spawning a new character (like from a spawn point), then you’ll want level blueprint logic to assign this variable to your character manually. You can do this easily setting “Expose on Spawn” on the variable, and feeding a ref to the spline actor in wherever your spawn logic is kept. Once you got that set, you’ll want a custom event that takes the container variable and finds the spline component to keep in the 2nd variable. Get the 1st, drag and pick GetComponentsByClass, set the Component Class to “Spline Component”, drag off the Return Value and “Get (a copy)” leaving the index as 0 (assuming there’s only 1 spline). Set your spline component variable to this output. Now you have a way to get data off this spline easily.
Check the image below for the most basic steps to get a movement system working. You’ll need variables for distance travelled, speed and to know if the player is trying to move forward. Speed x Delta Seconds in a ticking function helps ensure you move a distance proportional to your FPS. Note: Doing things on Tick is generally bad, but done here as a simple example to get you started. If you keep adding this onto your distance variable, you’ll be able to keep track of how far down the spline your player gets. A “Get Location at Distance Along Spline” node is a great solution to get back a world space location you can set as an actor location for your character.
Right - last part of your question is about character rotation. Just getting the location at a spline distance ignores rotation, meaning the char will always face in its original direction even if the spline path is curvy. This frees you up to apply the same 1st person input logic for rotation as a normal 1st person template guy (thru control rotation or other means). Which might be what you want. But know that if your path goes forward and then 90 to the left, the character will go forward and then side step left unless the player actually turns the char himself. If you’d rather the character turn with the spline and let the player also rotate further from there, you can use a “Get Transform at Distance Along Spline” to pull the forward tangent vector of the spline - but you’ll also want to keep track of the player’s yaw and add/subtract from that based on mouse input to apply over top (just like the distance stuff worked). Generally a separate gizmo isn’t necessary unless you have a specific use case for that. The node for turning your player would be SetActorRotation.
This is getting long, but hopefully there’s some ideas here to help get you started.
Wow, thanks a lot for the detailed answer. And yes I should have made it clear that I will want a full body character including bottom. Will this affect the method you posted? Il be honest a lot of the stuff you mentioned dont mean anything to me as I have 0 experience when it comes to BP. But at least I have a starting point where I can read up on stuff and watch some stuff. Anything in particular that might be helpful I should watch?
Thanks again for writing such a detailed follow up.