Angle between 2 CFrames

Hello!

I am currently working on a tank, and I want the turret to point where my mouse is located. A BodyGyro won’t work in this scenario because it will mess with the rest of the tank physics. I was hoping to use a motor6D or HingeConstraint, however I cannot figure out how to calculate the angle. Does anyone know how this can be done?

Angle between the base of the turret and mouse.

Roblox has a built in function for calculating the rotation so that a vector3 in one location will look at another vector3.

local function calc(v1,v2)
    return CFrame.new(v1,v2)
end

This will return a CFrame with the position of the first vector3 passed through and will look at the second vector3 passed through.

I know, but because the turret of the tank is welded to a moving model, rotating the turret in this way would not work because the turret is welded to the main body. Doing this CFrame would break the weld and the gun would fall off

Can’t you adjust the C0 or the C1 of the weld?

Thats the plan, but Idk how to calculate the correct angle for this adjustment.

You can still use CFrame:ToOrientation() to extract the angle and still have the same position with the C0/C1?

What’s the point of that code-block? It’s functionally identical to local calc = CFrame.new, but I don’t see why you need to make a function whose sole purpose is to call another function.

3 Likes