In my game, I have models that look a specific direction when using Cframe.LookAt(), but some models are offset by 90 degrees.
How do I change the way it rotates? I don’t want to manually make the script rotate specific models differently since I’m lazy, but I am genuinely clueless on how to change the way it rotates and why some parts rotate different than others.
I’ve tried rotating the primary part, the model itself, the primary part’s pivot, the model’s pivot, and nothing has led to change.
Here is how most models look V.S the model I have a problem with:
Try ungrouping and regrouping each model, this should have them all set to the same orientation relative to the parts. Then, hopefully they will either all be in the same orientation or all offset. Then you can just modify your offset to fix it! Tell me if this works!
CFrame.LookAt is kinda expensive to use and is gonna be nit very accurate/safe…
You should make primary part of a model and make sure they all have same direction if you want to center model etc for pivot to be in a right position.
try changing the PivotOffset in the models, maybe? Also try ungrouping and rotating the parts (lets say the parts are off by 90 degrees, you would ungroup the model rotate the parts by 90 deg and then regroup), or try adjusting the pivot offset by 90 degrees. Not too sure.
How are you rotating the model? Are you using PivotTo, SetPrimaryPartCFrame, or something else? Can you send code for this?
Maybe you could try setting the primary part to an invisible part and then rotating this part by how much it’s off, and then use SetPrimaryPartCFrame? Make sure you try with multiple rotations of the new primary part just to make sure. (This is deprecated but it’s all I can think of, if that doesn’t work then maybe you could send a reproduction file and I can experiment)
Also, you could try using the pivot editor in studio, that should allow you to modify the pivot of the model instead of using a primary part.
You should create a part placed at the center of the model and facing forwards, then weld the parts to revolve around that part as the main part and set it as the primary part of the model. This will make the model face the same direction as the part (to put it simply, it inherits the directions). Then try using :PivotTo(CFrame) to make it face forwards. Keep in mind that the direction will be based off of the primary part’s direction. If the model is going to face left, it will face towards the primary part’s left. If you already have a primary part, just make it face correctly.
If they all have faces, you could do something like this to ensure that the face always faces towards the goal:
local function faceCFrameLookAt(model: Model, faceDecal: Decal, lookAtPosition: Vector3)
local modelCF = model:GetPivot()
-- Get the look at cframe from the model to the look at position
local lookAtCF = CFrame.lookAt(modelCF.Position, lookAtPosition)
-- Get the look vector of the face based on which side of the head it is on
local faceLookVector = faceDecal.Parent.CFrame:VectorToWorldSpace(Vector3.FromNormalId(faceDecal.Face))
-- Get the rotation cframe from the face's look vector to the model's look vector (both in the model's object space)
local rotationCF = CFrame.fromRotationBetweenVectors(modelCF:VectorToObjectSpace(faceLookVector), -Vector3.zAxis)
-- Multiply the look at cframe by that rotation cframe
local finalCF = lookAtCF*rotationCF
model:PivotTo(finalCF)
end
The hinges show the different look vectors of the models’ primary parts.
Ended up fixing this from messing around, heres how I did it for anybody who also encounters this problem:
I added an attachment to the primary parts of both a working baby and a broken baby
The working baby had its X axis on the attachment going left when looking at it from the front, but the broken baby had its X axis on the attachment going backwards when looking at it from the front
I rotated the broken baby’s primary part until its attachment X axis was also going left when looking at it from the front
For good measure, I re-welded all of the parts to make everything move with the primary part
I’m pretty sure this only worked and the reason I had such issues is because I was changing the primary part’s cframe directly, not using PivotTo
I probably should’ve specified… lol