Math and Rotators?

Hey guys,

I’m trying to make a blueprint that rotates something X degrees over X time. Once it reaches it, it can either do it again immediately (so it spins constantly) or it can pause for X time before doing it again.

I started by using RInterpTo Constant and Set Actor Rotation. This works on the Z-Axis, but the X-Axis doesn’t move at all and the Y-Axis stops after 90 degrees and starts jittering. I’ve done some research and everyone says to use Add Local Rotation instead… but that doesn’t do the same thing so I don’t see how that’s a solution. When I tried that, my actor spun around at super speed because it’s not interpolating any more.

I tried to use interp to find where it should be at the end of the function and subtract the current rotation from that, giving me the correct rotation to add, but to my surprise, you can’t just do math with rotators like you can with vectors. I have no clue what I should do. Rotators seem so limited that I can’t really do anything with them. I’ve heard that Quats are better but I can’t seem to do anything with those, either.

Any suggestions?

You need to chose one specific application and show your code. Because rotation is a dungeon full of spikes and gremlins :slight_smile:

Seriously though, for instance your crazy spinning object when you used ‘add rotation’ is because you’re doing on a timeline, right?

1 Like

No timeline, just a repeating function.

This one is what I was trying to do initially. It works if I’m rotating on the Z-Axis but not the other two for some reason:

This one is the workaround that I found online, but it isn’t interpolating between the starting rotation and the target rotation, it’s just adding the target to the current every frame, which is an entirely different thing:

Sorry, those pictures are hard to see. These should be better:

If you want to do X degrees over X time, I’d would go for a timeline.

It will work if you calculate the start and end points before using the TL.

You calculate the end point using either delta( rotator ) or combine( rotator ).

As you’ve discovered, the another option, is only adding local rotation.

If you want to be able to do any kind of rotations using any method ( TL / interp ) without having to worry about weird transforms, then you need quaternions.

But how can I use quaternions? there’s the To Quaternion node, but once I have one, it seems I’m not really able to do anything with it. I’m trying to avoid Timelines because this will all be in C++ in the end, and I don’t think timelines are a thing in C++, are they?

Combine rotator adds them together, right? how do I subtract?

If you’re heading for CPP, then you have quats :slight_smile:

Subtracting rotators would be ‘delta’

Okay, so I should just do it in CPP then? Blueprints were only for prototyping anyway. I just have to learn how to use quats

I tried using Delta rotation but it didn’t work. Now it spins around wildly on all 3 axes, even though 2 of them are set to 0.

I can’t debug it for you because you’re only showing one part of a whole bunch of stuff you’ve got going on.

I don’t know what that other code is, and it’s not needed for getting to know delta rotation.

Can you just show what you would use to rotate a simple mesh? Once piece of code.

Or describe what you need?

If you want to go for CPP anyway, then rotators might the hitch needed to make the move.

For me, it seems, you either have to deal with rotation weirdness, or hide that weirdness in quaternions.

This is how I’m trying to rotate a simple mesh. I’m making a component that can be attached to meshes to make them rotate. The one that isn’t working is a fan. The fan is upright and the player is supposed to run between the blades as it spins, but it won’t spin right. It will only rotate on the Z-Axis. I don’t want to just add to the rotation because that makes it spin super fast and I can’t track where it is. Interpolating allows me to set a target and do something when it reaches it (i.e. spin 90 degrees, then stop). It also allows me to control the exact amount of time it takes to rotate. As far as I can tell, RInterpTo Constant is the only way to do that.

You could try and rotate a component in relative space rather than going for the actor in world:

Spin

Just have to add a tag to the component you want to spin. This will not work with the root component.

I wonder if you can upload an FBX on the fan here, I will have a go.

It’s probably because the pivot is rotated incorrectly, and the easiest solution is to fix the pivot. You can do that in the engine modelling tools.

You can also do this with the addition of rotations and a timeline. I will have a go if you upload it. Or just show a pic with the pivot clearly, and I’ll make something similar :slight_smile:

I’m just using cubes for now lol

1 Like

There is also the rotation component.

But yeah the best may be with quaternions which could require C++ but you can also do completely arbitrary axes.

Quaternion has a function to go from axis angle representation to quat. Axis can be just X, Y, or Z, or something completely arbitrary that points in any direction. It’s basically a normalized direction vector.

You can then animate the rotation on its own in whatever way you want.

Then set the object’s quat from that angle that is animated and the axis you choose.

It makes sense that you’re having issues with Rotators because of how they work and gimbal lock.

So I made a fan the same way you did, we both have excellent modelling skills :slight_smile:

This is the code

I can set any values for the speed, rotation amount and delay between rotations on the BP in the level

fan

( the jump is just the GIF )