How do I make it so a weld adjusts so the Part1 it's welded to moves to point towards something?

Sorry if this sounds rather convoluted, but I have a rather complicated CFrame related question.

How can I calculate the CFrame at which I would need to set a weld’s C0 property to make this turret face a part? (or any welded part system for that matter)
image
All of this is unanchored, the idea is that the car would be able to move around freely, without the physics of the turret causing any issues either (so no BallConstraint/BodyGyro solutions please).

WeldConstraint’s wouldn’t work very well either since you can’t directly edit their value, and although I could try to set the part’s CFrame, it would likely drift off as the car starts moving.

From what I know there is a lot of CFrame API that should be able to help me here, but I’m just not 100% sure which to use. I know how basic CFrame API works such as Angles, lookAt, new, etc. If anyone can point me in the right direction that would be awesome.

2 Likes

I’m not to sure but try doing:

CFrame.new(Part1.CFrame, YellowSphere.CFrame) --change 'Part1' and 'YellowSphere' to the parts you want

The reason I only put two positions in the CFrame is because when you put two it changes the 1st position to face the second. I’m not fully sure if this will work but try it out.

This is deprecated API, you would want to use CFrame.lookAt for this, not CFrame.new. Like I said, I need to edit the weld, not the part CFrame.

1 Like

Oh, I’m not really sure, sorry about that.

weld.C0 = weld.Part0.CFrame:ToObjectSpace(CFrame.lookAt(weld.Part1.Position+weld.C1.Position, yellowSphere.Position))
5 Likes

Had no idea it’d be this simple, thank you so much!

I came close at one point but it seemed to get confused when it got rotated on the X/Z axis. This one doesn’t seem to have that issue.

3 Likes