Hey guys I need help to find an offset to rotate the gun turret to the Camera CFrame. how can I do this?
So it only rotates to the direction camera is facing?
game:GetService("RunService").Heartbeat:Connect(function()
local X,Y,Z = Camera.CFrame:ToOrientation()
local hit = Mouse.Hit;
local direction = Camera.CFrame.Position + Camera.CFrame.LookVector.Unit * 5000
local rootCFrame = Gun.Support.CFrame;
local rotationOffset = (rootCFrame - rootCFrame.p):inverse();
Gun.Support.Rotate.Transform = rotationOffset * CFrame.new(Vector3.new(0, 0, 0), Vector3.new(direction.X,direction.Y,direction.Z))
if (Camera.CameraSubject ~= Gun.Gun.Aimpart) then
Camera.CameraSubject = Gun.Gun.Aimpart;
end;
end)