Blueprint Quaternion Library

**What is this? **

Simple. Have you ever wanted to make something with a heavy focus on rotations? Think of something like a flight sim. Would you like to do so in BP? Well then the Blueprint Quaternion Library is for you!

**But what does it really do? **

It merely exposes the internal functions of the Quaternion type to Blueprint. That’s it.


- I've only tested this on Windows, but I don't really do anything that should prevent other platforms from working. 
- Likely not, and if support for an external tool lies outside of BP - ie an engine change - then no.
- Currently you'll have to explore via the BP context menu and tooltips. I may make some example videos or a formal API reference, though the [C++ api]( will let you see some of the functions that I've exposed. I won't be teaching you how to use Quaternions or what they are - there's resources for that on the web already.
- Feel free to suggest it, and if it makes sense I'll consider adding it to the plugin.
- Not a question, but uh. Yeah, find a way to send me the output log and if its a simple fix I'll fix the plugin. I can't really test all platforms so I only really support issues with Windows currently.

Hey. Here’s that quaternion constant interpolation you wanted. There’s probably a few small bugs but on a practical level its working.

The blend is just a simple tool to say when the constant steady motion would begin to blend. In this way, you get a constant rate of rotation, but the end before it stops can be smoothened. I find 0.2 is a really nice value but you can set it to just 0 if you want a true constant rotation.

I’ve still not had it perform a set number of rad/deg a second yet. Not 100% sure how I’ll do that yet.

I’m not great with quaternions but I really hope this helps you out.

Thanks! I’ll probably do my own version of this, but its awesome that you’ve got a working solution.

Can you think of any other missing functionality? I’ll see if I can address these basic shortcomings all in the next update.

The capacity to do this with a number of either degrees or radians a second. The blend functionality is a biggie because its something I seriously think UE4 has needed from the beginning and doesn’t have. A huge thing a lot of people want is the ability to put in a directional vector, an up vector and have it spit out either a rotation or a quaternion (which in the former is easy enough to do just using vector composition). If you did one with a look at rotation as the forward vector and then the arbitrary up vector, you’d be saving a lot of people huge headaches since the most common problem when working with advanced math in UE4 is just aligning an object to a surface normal (typically a character). Not hard but its something a lot of people spend a while scratching their heads trying to solve.

Its not part of quats but the only other thing I can possibly think of is a way to rotate an object from a center which is not its default centre – for example, an orbit. This would need to be done in a way which wouldn’t violate the **** out of basic collision math provided by UE4’s existing systems and may in itself be an idea for a plugin.

Also now realising Blueprints don’t support doubles and I’m trying to do calculations in them which is a huge headache. Any chance of a doubles library?

Update: Woohoo! KeshUE4FundamentalTypeWrapperPlugin/KeshUE4FundamentalTypeWrapper.h at master · Daekesh/KeshUE4FundamentalTypeWrapperPlugin · GitHub

Well, hey, I finally did the update thing. Woot.

I was trying to figure out how to make a quat lookat function (-z) but running into some issues (please apologize the cringyness of my mathematical ignorance):

Making a quat from XZ or YZ only rotates the origin along one axis.

X axis Y axis

Composing the two quats results in the origin performing a cool breakdance

Making the quat from Z flips the X & Y axis at the 180 degrees mark (Gimbal Lock?)


Averaging the axis works for the most part but there are target locations that prompt the origin’s signature breakdance

I’ve been trying to implement something along these lines, but so far have failed:

Quaternion lookAt(const Vector3f& sourcePoint, const Vector3f& destPoint, const Vector3f& front, const Vector3f& up)
Vector3f toVector = (destPoint - sourcePoint).normalized();
//compute rotation axis
Vector3f rotAxis = front.cross(toVector).normalized();
if (rotAxis.squaredNorm() == 0)
rotAxis = up;
//find the angle around rotation axis
float dot = VectorMath::front().dot(toVector);
float ang = std::acosf(dot);
//convert axis angle to quaternion
return Eigen::AngleAxisf(rotAxis, ang);

I am currently testing other methods based on adding to the quat rotation but the solutions so far represent the epitome of spaghettification and are anything but elegant.

No worries! You shouldn’t need to be a math whiz to use rotations.

Not exactly. The order of the axes matters because the first axis will retain its direction, while the other axis is adjusted so that the entire coordinate system remains orthonormal.

This is because each frame you’re using the previous frame’s rotation as input to determine the rotation it should take. If you instead cache a rotation (or basis vectors) you’ll get a more usable result.

This is not gimbal lock, there’s just no way to infer where the other two basis vectors should be, and so it sort of just makes an assumption. Try ZY or ZX for your rotations.

(better gif linked here)](

I can’t thank you enough for putting up with me and provide such eloquent answer ImmutableLambda. Not only your suggestion of making from ZX works perfectly, but also thanks to your explanations I am able to grow as a better developer.

Hey, I’ve been using your quaternion library and I like it a lot but I’m having an issue. I’m trying to make a pawn that can walk up walls and on the ceiling. Right now I’m raytracing down from the pawn’s up vector to get the floor’s normal. I’m then trying to get the smallest rotation to match the new normal and update the pawn to that rotation. You can see how I’m determining my final rotation below. “Owner typed” is my pawn and New Up is the normal result from the ray trace.

I then apply it to my pawn using the following code.

This works most of the time but has real difficulties once the normal is pointing directly down. I’ve built the following movement test map.

If my pawn walks up the ramp on either the left or right but then tries to come down the ramp in the middle the rotation completely breaks and it starts rotation all over.

Any advice would be greatly appreciated. This has been driving me crazy.

Sorry to hear that you’ve been having trouble with this.

Just a hunch, but do you have your pawn using control rotation whatsoever?

Hello @ImmutableLambda

I’ve been trying to use your plugin to go from a rotation to a quat and back to a rotation. In the screenshot I’m printing the world rotation of my component and the quat to euler vector of the component world transform… How can I get the To Euler to be the same as the world rotation? I’m definetly lost in terms of quaternions, even after reading up on them… Cheers!

Hey @ImmutableLambda thanks for replying, I only now saw it. I figured out my problem. It turns out I was using an “From XZ” node where I needed to be using a “From ZX” node. Everything is working perfectly now.


It’d appear its just an issue of the output format and nothing wrong with what you’re doing!

In addition, you should be able to get a rotator from the Quat. Just use the ToRotator node.

Glad to hear it!

Hello @ImmutableLambda, thanks for the reply and wow. I feel stupid. I didn’t even notice that the values were the same, just shifted around (and with more decimals). “To Rotator” works beautifully as well. Thank you!

Hey @ImmutableLambda

thank you for the plugin. The whole rotating with gimbal lock and other problems have always been an issue for me. Tried to tackle it again with your plugin, basically having a spaceship be able to rotate freely without issues.

It seems I can’t simply apply the axis input to “Add Component World Rotation” or “Add Actor World Rotation”, iirc just X (input, 0,0, 1) actually gave me any rotation. I couldn’t get X and Y to work properly. Being absolutely lost I tried “Add Controller Yaw Input” etc again with a modified PlayerCameraManager that allows rotating without limits. But then when I rotate in one axis followed by another (say Roll 90° and then input Pitch) the axis is wrong (Yawing). I’ve attached a screenshot of how it would “ideally work”. Now I’ll try going back to Quaternions again, but could you give me a tip how I can get this going by using Quaternions? I tried making rotations from the axis, but… ye. Let’s say I don’t know what I’m doing with Quaternions (after watching multiple videos), especially in relation to the actor.

Heya I purchased the Blueprint Quaternions Library and willing to “PAY” someone to help out, However I’m not sure if Quaternions are what we need.
it doesn’t seem to do what I was hoping, which is perfectly ok, I’m sure we can use it for other things! Perhaps Its because i lack the knowledge how to put it to work for our cause.

When I print the Numbers data to screen, it seems to have the same issue as the Euler Angles where the numbers data jumps all over the place, but just adds in a 4th axis.
Anyways Below is a copy paste from another Forum post to outline the situation, and again, I’m also willing to pay someone to figure things out for us.
Pretty Desperate and at wits end with this whole thing.

[SIZE=13px][SIZE=16px]Our team has Been working on and off this past year to figure a way around a rotation related issue we have been having.
Now that our game has some major progress, this limitation is really starting to hold us back from finishing up a few important features for our game.

Anyways, We need to get Rotational data from XY&Z from 0 to360 and or beyond 360 without the data jumping all over the place. [/SIZE][/SIZE] (We need to have Axis data gathering or rather Data Translation to linear data and be able to lets have for example 45 degrees on X and than rotate Z 90 degrees but keep the X displaying the 45 Degrees, and if we add in Y of 190 degrees than the Z and X numbers data should remain unchanged as well.)

[SIZE=13px][SIZE=16px]We need it to drive the sprite animation system that we’ve already done, part of which is based on the rotation of an actor,
The sprite system has some sprites that have 360 degrees worth of angles rendered out to a sprite sheet. Everything works so far with the Sprite system. However, the Rotation Values are jumping all over the place.

Kind of a recap: We need to locally rotate Z to 45 degrees, Y to 250 degrees, and X to 300 degrees, each needs to give out that exact number of the rotation even when combined like described above so we can use that to select the correct Animation frame based on the model’s rotation for the 360 degree Sphere rendered Sprite system. Not just that, but we also need to drive mesh to mesh rotation values but lock out specific Axis.[/SIZE][/SIZE] To better explain what limits I’m hitting here and to help visualize… ( I figure due to Gimbal lock)

[SIZE=13px][SIZE=13px]First lets Make an actor BP [/SIZE][/SIZE] and lets do this:
*add a mesh inside that BP.
*get the mesh or the root of the actor.
*get the world rotation.
*split the pins so we get X,Y, and Z.
*Round each of the Values so that its less confusing.
*print string for each of the rounded X,Y,and Z so that when we run the game the data is at your disposal.

Now lets go into the Editor,
Place the new BP actor in the level, and don’t fire up the game yet, but grab the Rotation gizmos directly in the viewport and rotate them, notice how the data displays next to the Gizmo goes from 0 to 360 and beyond? This is the data that we need to be able to grab inside the BP or C++. ( don’t look at the Details panel data btw)
Ok now!
fire up the game in viewport mode, press F8 and lets grab and rotate the Y axis on the positive rotation,
We will see some funky results which first start when reaching every 90 degrees.
Here’s a break down of what i see happening as i spin a mesh 360 degrees:
At 0 to 90 degrees: that works ok ( X: 0) (Y:0 to 90 as we spin) (Z= 0)
At: 90 to 180 degrees: (X= -180) (Y getting: 90 to and back to 0 as we spin) (Z= -180)
At 180 to 270 degrees: (X= -180,) (Y is getting 0 to -90 as we spin) (Z= -180)
At 270 to 360 degrees: (X= 0) (Y is getting -90 to 0 as we spin) (Z = 0)
The thing is that i need to have a consecutive numbers feed back from Y axis 0 up to 360.
I can’t use X or Z because they are feeding other parameters (For example i can spin 0 to 360 on each X and Z and they are not jumping around),
So my question: Is there a way to cheat around the Y axis issue or some kind of solution i can use to translate above outlined issue into consecutive degrees digits for Y axis ?

Here is one failed attempt to get the Y Axis to go from 0 to 360:
Its failed because the X and Z values still interact with the Y Axis. Anyways! Having the rotation data correctly display 0 to 360 and Beyond and be divided for each axis is something that we really need for our project so that each axis does not interfere with other axis.

Just a dumb, initial, sanity check - but have you tried getting the rotator and splitting the pins, running each component through the ClampAxis node and using that? Seems super simple and like you should have tried it, but just thought I’d ask. Probably wouldn’t work because it doesn’t actually factor the other components in (so they’d be inaccurate).

Failing that, take the rotator you wanna use but the values aren’t in your range, and see if you can’t make a quaternion from its forward & up vectors (“Make from XZ” - any of these should work) and convert it to euler (gives you a vector not a rotator).

Hello @ImmutableLambda
I’ve bought your plugin because of a problem i face.
I would like your help if possible as i don’t know a lot of quaternion me myself.

so i have a cylinder and i want to rotate around the up vector as its axis of rotation when i press up or down arrows or swipe on touch.
and i want to rotate it around the right vector when i swipe left or right, or pressing left and right keys on keyboard.

My current setup is this

and this is the cylinder i want to rotate.

So basically, i want when i press the up or down keys (or in case of mobile to swipe up or down) is to rotate around the green arrow
and when pressing left and right i want to rotate around the red arrow.

my current setup with quaternion is

which doesn’t work.

i would really appreciate your help.

Many Thanks.