Make Part face another part with CFrame.Angles?

Hello devs, So I have been thinking about this for long, and I want to know this if I will need this in future, because CFrame.LookAt sometimes offsets, and only way to fix it is to use CFrame.Angles, so How do I? And don’t say “Why would you want to reinvent wheel?” or I will ignore it.

1 Like

Have you tried

part.CFrame = CFrame.new(part.Position, target.Position)

?

1 Like

or

 part.CFrame = CFrame.lookAt(part.Position, target.Position) 
1 Like

That doesn’t answer my question.

What do you exactly mean then? Because you say that CFrame.Angles is really the only solution to fix it, unless if you’re using some sort of SpecialMesh object that you have to use CFrame.Angles() in order to properly make the Part look at that Target

local TargetPart = workspace.TargetPart
local Part = workspace.Part
local RotateX, RotateY, RotateZ = 0, 0, 0

Part.CFrame = CFrame.new(Part.Position, TargetPart.Position) * CFrame.Angles(math.rad(RotateX), math.rad(RotateY), math.rad(RotateZ))

Sometimes CFrame.LookAt and .new makes weird offset, thats why I need to use CFrame.Angles

I made a function using Egomooses advanced CFrame trick to get the rotation between two vectors.

Using this trick I can align a parts lookvector to face towards a desired lookvector I want. I believe I used it in this plane seat I made, or maybe it’s commented out the two versions one with CFrame.lookAt and one with this new method I was testing out.

On a side note I really dislike this post

No code, screenshot, video, reproduction file explaining this offset problem.

No one here has a clue what you want so don’t expect a good answer that will solve all your problems in one go in return.

1 Like

Because I wan’t to know HOW to use CFrame.Angles not to solve my code, my code is hand script, it moves to mouse’s position.

If you’re moving the Part with the Mouse, why not just filter the Part(s) you’re moving then with Mouse.TargetFilter? It’ll ignore the overlapping offset of the current Parts you want it to ignore

Now that you include an example hand movement which you should have mentioned in the beginning of the post.

I’m able to come up with a related topic.

My Turret controller which solves this offset issue using a turret attachment, still uses CFrame.lookAt but the gun is able to point towards the target with no offset. You can apply the same with a hand as its both Motor6Ds.

TL;DR:

The CFrame.lookAt position must start from the tip of the arm or the gun barrel in my case in order for there to be no offset.

1 Like

Already did that. Soo yeah. And it still didn’t do anything.