Weird flipping with CFrame.lookAlong

i’m trying to make a tidally locked moon, and I want to use CFrame.lookAlong to have it always facing the parent planet. However, it flips over every 180 degrees, and I have no clue how to solve this

there seems to be no issues with my line of code, this was also a problem in the past where CFrame.lookAt was doing the same thing, except just instantly snapping upside down.

script.Parent.CFrame = CFrame.lookAlong(body.Position, center.Position, Vector3.zAxis) * CFrame.Angles(0, 0, math.rad(90))

increase math.rad to 180, if that doesn’t work, do 360
it’s the only issue i can see

it still doesnt work sadly

also i should clarify that the math.rad is so that it is rotated at the right direction, because it was facing the wrong way without it

hmmm, what if you normalize the second parameter (center)
lookAlong’s second parameter takes a direction, what happens if you do:

center.Unit -- this probably won't work

local direction = (planetBeingOrbited.Position - moon.Position).Unit
-- you might have to flip the vectors that are being subtracted, i could've done it the other way around

CFrame.lookAlong(moon.Pos, direction, whateverHere)

nope, it does the same. I flipped the vectors and also changed a lot of the variables and nothing really changed. center.Unit didn’t work either

I’m not sure where the up direction in that video is, but usually, “up” would be Vector3.yAxis, not Vector3.zAxis.

1 Like

CFraming at exact 90° angles can lead to gimbal lock of the axes. Basically when your rotation ends up being exactly 90° one of the x, y or z axes align exactly with one of the others causing object to flip around like that.
Search ‘gimbal lock’ in the forums for explanations and Solved posts about it because it’s above my ability to fix it.

1 Like
script.Parent.CFrame = CFrame.lookAlong(body.Position, center.Position, Vector3.zAxis) * CFrame.Angles(0, 0, math.rad(90))

This is erroneous. the second argument expects a look vector - some direction vector that the cframe tries to copy. while remaining in location.
If you want it to perpetually look at something, you should be using CFrame.LookAt.
(CFrame.lookAlong is not a good method to be honest. yet to find a usecase for it.)

2 Likes

yeah, nots7d already clarified that first part.
thanks though, i didnt know it was a bad method

i didnt know what this was called, ty
ill look more into it, i have found a lot of posts on this so far but i havent gotten a good result yet

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