I’m currently working on a shooting turret which is supposed to rotate with the camera movement. But the whole model should only move left and right while the gun itself moves only up and down. I should be able to achieve this by setting the rotation of the whole model to look at the mouse position coordinates except on the Y axis and the rotation of the gun to the same but just the Y axis.
game["Run Service"].RenderStepped:Connect(function()
local turretPivot = turret:GetPivot()
local gunPosition = turret.gun:GetPivot()
local angle = CFrame.lookAt(gunPosition.p, Vector3.new(gunPosition.p.X, mouse.Hit.Y, gunPosition.p.Z))
turret.gun:PivotTo(angle)
turret:PivotTo(CFrame.lookAt(turretPivot.Position, Vector3.new(mouse.Hit.Position.X,turretPivot.Position.Y,mouse.Hit.Position.Z)))
end)
But when I do that, the position its trying to look at is too close to the origin so it doesn’t work.
What I have done is set the gun rotation to all the axis but that doesn’t give the desired result.
game["Run Service"].RenderStepped:Connect(function()
local turretPivot = turret:GetPivot()
local gunPosition = turret.gun:GetPivot()
local angle = CFrame.lookAt(gunPosition.p, mouse.Hit.Position)
turret.gun:PivotTo(angle)
turret:PivotTo(CFrame.lookAt(turretPivot.Position, Vector3.new(mouse.Hit.Position.X,turretPivot.Position.Y,mouse.Hit.Position.Z)))
end)
What am I missing? I’m still pretty confused by CFrame sometimes so I’m sorry if this is trivial.