Weird rotations along spline

Hi!

I am trying to create a simple project where a train follows a spline, easy. Everything is working, but at some points, the train is rotating up and down really fast for no obvious reason. I checked spline points, there are no sharp curves or something like that.
I also dynamically spawn railroad mesh along the same spline and there are no weird rotations or curves.

Here is a video demonstration:
https://youtu.be/CTOWvyNvMBU

Here is how my railroad looks at that location where weird rotations happen:

Also, here is my blueprint code:
Spline location and rotation logic posted by anonymous | blueprintUE | PasteBin For Unreal Engine

This method is called from Tick event

I would really appreciate any help because I am struggling with this for days.

Thanks!

I think it’s possibly this construct

If you want the train to be further along the spline, you have to just add to the Distance variable

you can’t add a vector afterwards :slight_smile:

Even if it’s just the height of the car, I don’t think adding a constant will work, because it’s not taking spline rotation into account.

Hi, thanks for the answer!

This offset is actually for Z axis, I want the train to be offset from the rail actually and this does not change in runtime at all.

Also tried without the offset, and the same thing happens :confused:

1 Like

Ok, so not that then :slight_smile:

I was just saying, that if the spline is twisting, then Z needs to be relative to the spline. It’s not just up.

Is the spline smooth? Maybe it’s just bumps in the spline.

Yup, I agree with you. I do not plan to have any twists on the spline but I should keep that in mind.

Regarding the spline itself, it is just a straight line:

Also, I have a bridge in front of this image, and rails (spline) is curving upwards (elevating) and the train does not glitch there at all. Also, there is a long straight rail section, nothing happens there.

Btw, since I am new to Unreal, here is how I configured my Train actor, in case I misconfigured something:
image

Train Static mesh is the mesh you see, Speed Lever static mesh is just a mesh inside the train that you can use to start/stop the train, and the Trigger box is just that, it does not collide with anything.

Another thing I noticed, and this is really weird for me.
I tried printing train’s actor rotation every frame, and pitch rotation ranges from 0.1 to 0.3, but at the moment when the train “jumps”, it goes to around 2.5:

Isn’t this just 2 degrees? I guess I wouldn’t even notice rotation this small, right?

1 Like

Could be. A couple of degrees is very noticeable when you’re riding on top of it, I think :slight_smile:

EDIT: You can’t cut the pitch out, by why are there these little variations, I wonder…?

No idea. I just deleted two points I had there and those bumps do not happen anymore, but I still have no idea what could be the cause.

Anyways, I really appreciate your help, thank you!

1 Like