CFrame.LookAt upVector doesnt work properly

So I am making this rocket projectile, and wanted to make the rocket “look” the way it is going. I have alrady calculated the position I need the rocket to look and all this stuff. But when it comes to actually rotating the rocket model, there is one issue.

The issue is that the “front” of the CFrame isnt the same “front” for the actual rocket. Basically it looks like this:

  • Red color is the front of the CFrame
  • Greenish-blue is the front of the model

You probably see where I am going with this, and now, when I did some searching, I noticed there is an upVector parameter for the LookAt function. Maybe it was just something I missed, but no matter what I set the up vector to, the rocket always faces completely wrong way.

  • When the vector is default (0,1,0), the rocket faces straight down, when (0,-1,0) its straight up.
    –Example of 0,1,0:
    image

  • When the vector is default (0,0,1), the rocket faces straight left, when (0,0,-1) its straight right.
    –Example of 0,0,1:

So one would be thinking to put the upVector to the X axis, well, nope!
Example of 1,0,0:
image

Up to this moment, the Y and Z vector made pretty much sense (Y changed it up or down, Z changed it Left or Right) but setting the X as upVector just doesn’t make any sense at all. The rotation with the X as up vector behaves almost as with Z being the up vector.

I also tried mixing several X,Y,Z values together as an upVector, but couldn’t find any combination to come even close to the desired one.

I will really appreciate any advice or help!

1 Like

When constructing a CFrame via CFrame.lookAt(), the first and second vectors supplied only provide one axis of the rotation matrix, but that matrix requires three axes, so the rest must be derived from some other data. The problem is that to solve your issue, you need the direction vector to be different, not the UpVector, since the only vector that is guaranteed to be represented faithfully in the resulting CFrame is the provided direction; the rest of the axes are derived from it.

The easiest solution is to just generate the CFrame via CFrame.lookAt() and then multiply it by another rotational CFrame to get the desired result. If I’m understanding your model correctly, it’d be something like CFrame.lookAt(...) * CFrame.Angles(math.pi / 2, 0, 0).

A better solution would be to configure the pivot of your model so that Model:PivotTo(CFrame.lookAt(...)) would have it facing in the correct direction inherently.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.