Rotating a character along a spline

I’m trying to create a grinding system similar to THPS. I need to make the character rotate perpendicularly to the spline that controls the grind. While I’ve been able to get the character to sort of do this, sometimes it will reverse directions instantly after too much rotation. I assume I need to use quaternions somehow, but I don’t understand them at all. What do I need to do to fix this?


This runs on tick

1 Like

@ClockworkOcean sorry to rope you in, but you’ve really helped me in the past. Do you have know what I might do?

1 Like

There’s two things to consider here

  1. If the spline wraps back on itself ( like a roller coaster loop ), no chance, because of a bug ( I think ) with the way the editor handles splines.

  2. If that point is covered, you can do it no problem but, you can’t split open rotators and fiddle with them :slight_smile: Rotation is a strange thing and the rotator nodes know how to handle it. You need to code it only using ‘add rotator’ nodes.

Tell me if you need a bit more info, but can’t give an example rn.

So, instead of

try

and you’ll need to try it both ways around, because you will not get the same result

That covers most things, I’ve found :slight_smile:

1 Like

This seems to work for the most part. It totally breaks if I attempt to put an rinterp on there though. But that’s a problem for another day lol.

1 Like

Maybe show your code. It has to be rotators the whole way :slight_smile:

Sure, thank you. This is what I’m working with.

Basically, this will make the character face perpendicular to the grind rail. Return Value 1 is the movement vector and Return Value 2 is the perpendicular angle. It works fine without the Rinterp, but doens’t look very good as it snaps instantly. Rinterp will cause the character to spin in circles on the rail if the interp speed is low, and kind of just sit at an angle if the speed is high.

It’s almost certainly this

Like I say, you can’t tamper with them, I’m afraid :slight_smile:

So I should use the delta node to compare rotators? Or are there other ways to compare them?

1 Like

You’re not just comparing, you’re changing it, right? :thinking:

That’s why the character is suddenly changing orientation, if you suddenly add 100 to an axis?

Are you trying to rotate the character in a constant way along the spline? So as you go along, the character rotates, a bit like a corkscrew?

Yes, sorry the image is a little low resolution, it’s actually 180deg.

So I was trying to make the character face perpendicular to the rail that they grind on. That’s not that hard using the Get Right Vector node from the spline, but it means that the character will always face the Spine’s right vector. So if I want him to face the opposite direction, like would happen if he approached the rail from it’s right vector, I have to get the opposite of his right vector.

Yes, the character rotates constantly when the interp speed is low. I’m basically just trying to smooth the transition between his rotation when he’s off the rail to his rotation when he’s on the rail.

1 Like

If you want to switch things around, get in there early on. Instead of just taking the right vector, just take the right vector and multiply it by -1. Then you don’t need the math.

Also, instead of just ‘make rot from X’, you can try one of these nodes

image

You get to take rotation from the spline, and specify a vector from your player. In this case, you probably want the spline vector first, because it has priority. Player forward vector might be a good starting point.

Yeah, I don’t know. I think my problem is that I don’t really understand what these nodes are doing. How did you learn about this subject?

1 Like

By trial and error and guessing mostly :rofl:

The nodes with 2 axis like ‘make rot from XY’ are saying 'I will take the X vector you give me as the main orientation, but will try to also correct as much as I can using the Y one also.

So here

image

you can use, for example, ‘make rot from ZX’. Give it the Z ( up vector ) from the spline ( main thing you want ) + ‘get actor forward vector’ from your character ( the way your character is facing ).

Best of both worlds :slight_smile: So, in your character you would say

1 Like

If I take this dummy and put it on a spline component

Then I can make it rotate once around the spline length, using this

Notice that I added -90 in Z because we want the dummy Y to point forward, not X. And then I also add the rotation ( 0 - 360 )

spline

1 Like

This helps a lot. Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.