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.
@ClockworkOcean Unfortunately that’s not quite right. 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 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.
As i wrote (for learning) use setup with 2 extra components.
Hierarchy of components should look like this:
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:
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?