I’m trying to have a static mesh component of an actor face towards a location in world space.
The function I have so far works fine if the actor is on a flat horizontal surface, but when on a slope (so it’s Pitch and Yaw are != 0), the rotator doesn’t point accurately. Code:
simulated function PointMeshCompAtWorldLoc(vector worldLoc)
{
local rotator faceToLoc;
faceToLoc = Rotator(worldLoc - Location) - Rotation;
MyMeshComp.SetRotation(faceToLoc);
}
Anyone know what I’m missing here? Thanks in advance.
Open up Object.uc and do a search for “Quaternion functions” and you’ll see a comment with a bunch of functions under it. That’s your toolbox. I think you’ll want to do this:
simulated function PointMeshCompAtWorldLoc(vector worldLoc)
{
local rotator faceToLoc;
local Quat QuatToTarget;
QuatToTarget = QuatFindBetween(Location, worldLoc);
faceToLoc = QuatToRotator(QuatToTarget);
faceToLoc -= Rotation;
MyMeshComp.SetRotation(faceToLoc);
}
Thanks for the suggestion. I wasn’t able to get it to work correctly though. I ended up deciding to keep the actor only rotating it’s yaw, so that i could continue using my original function. And then just rotate other smc’s it has to simulate the actor rotating.
I’d like to revisit it at a later date to implement the proper solution, but for now I’ll have to leave the hack solution in place, which works fine. Frustrating to not solve it though…