Trying to get a LookAtRotation without roll when the origin actor is rolled (90 degrees)

I have a character whose head turns to look at certain objects in the scene. This works fine as long as the character is on the ground, but the character can also walk on walls, which is where the problem shows up. I need to calculate a relative rotation in Pitch and Yaw with no Roll while oriented sideways to properly rotate the character’s head.

Here’s my current BP, I’ve also tried using FindLookAtRotation instead of MakeRotationFromAxes. Either way works from the ground, and either way is incorrect in the same way when on the wall.

I’m not opposed to writing some code to get Quaternion math into my BPs if that’s what’s needed, I just don’t have the knowledge to understand the calculations required.

I think you need to use quats in order to correctly rotate head.

I never done it in blueprints in ue, so i cannot help more.

Well like I said, I’m not opposed to writing some code. I’ve already started looking into Quaternions, it’s just a bit beyond my ability to understand which exact calculations I need to make.

1 Like

What about ( @Deiain )


The totally realistic character is available for a small fee… :wink:


@ClockworkOcean Unfortunately that’s not quite right. :frowning: Not sure why it’s working differently from your gif, maybe something to do with my head sockets. (It’s not working when wall-walking either, but here you can see it’s not working on the normal ground.)

You may need to adjust which axis you’re omitting / using, depending on how the pivot of your head is set up.

You want that small robot to rotate its head somehow realistic?

If so, then robot as humanoid has probably similar neck setup to us. Which means it cannot rotate head like it was freely rotating ball on top of body. (freely rotating ball could flip upside down if you rotate it over pole).

So for “humanoid” rotation you should create “dead zone” like max head “rotation up” to 70-80deg and no more. Then rotate horizontally around with some delay (interpto etc).

And you can do this by placing two components between body and head. one used for each part of rotation.

@Nawrot Yes, that’s how it’s really set up. I simplified the blueprint for the sake of posting here. The skeleton has a socket for head pitch and one for neck yaw, and i’m taking the ultimate rotation calculation into the animation blueprint.

Still struggling with this. :frowning:

As i wrote (for learning) use setup with 2 extra components.
Hierarchy of components should look like this:

  • root
    • horizontal rotation component
      • vertical rotation component

Because you want something similar to humanoid neck and head setup.

Split rotation into 2 separate rotations:

  • rotate horizontal component so head always faces target in horizontal plane
  • and then vertical rotation that has limits like our head has for eg -15 deg to 80 deg

then solve both rotations separately. This will give you human like head tracking.

To get rotations:

  • get location of head and target, multiply both by vector [1,1,0] you get those locations on horizontal plane, now it is matter of simple trig, or get look at rotation node
  • almost same can be done for vertical rotation: you get triangle that has base equal to distance (on horizontal plane,) between head and target and then height difference of head and target. Simple triangle.

When constructing “look at” you pass in a “forward” and an “up” vector.

Use the “up” vector of the character-walking-on-wall, and the forward vector as the vector from the character to the look target.

What you get out will be the (world space) look at direction, from the point of view of the wall-climbing character.

If you want to apply this to a head bone, you have to make sure you apply it in word space, OR pre-apply the inverse of the world-space rotation of the neck bone it’s parented to before applying it.

Btw, the math for “find lookat orientation” isn’t particularly crazy. If you don’t want to use the built-ins, you can do it yourself pretty easily.
Given two points, “eye location” and “target location,” and one vector, “up direction of looker,” you do this:

Vector Forward = Normalize(TargetLocation - EyeLocation);
Vector Right = Normalize(Cross(UpVector, Forward));
Vector RotUp = Cross(Forward, Right);
Matrix Rotation = Matrix(Forward, Right, RotUp);

(This assumes X-forward, Y-right, Z-up, which is the general left-handed Unreal coordinate system, and you’d need to translate the actual functions to whatever C++ or Blueprint you’re using.)

Everything I’ve tried and that’s been suggested gives me the same result:

The head appears to have the opposite yaw that it should have while walking on the wall. It works perfectly while on the ground.

Another post about Looking at an object with a lot of suggestions on how to do it and none of them actually working. The problem is we are having something look at an object which uses Rotators which are Eulers and that is causing the roll effect. We need to use Quaternions for looking at objects.

Is there not a Quaternion approach for a look at mechanic with Unreal?

I struggled with a similar issue. You have saved my life!)

1 Like