How to limit cframes angle if its not bound to anything

how do I limit a cframe lookat if the cframe lookats position is constantly moving because its in a car.

	handle.WeldConstraint.Part0 = nil
			
	local cf = CFrame.lookAt(turretcontrols.PivotHandlePart.Position, Vector3.new(ray.Position.X, turretcontrols.PivotHandlePart.Position.Y, ray.Position.Z))
		
	handle.WeldConstraint.Part0 = turret.TurretMain

You can try math.clamp(number,min,max)
Here’s a post about it:

nvm I figured it out, I used object space and simply checked if the handle was within angle limit and if so then move it

			local cf = CFrame.lookAt(turretcontrols.PivotHandlePart.Position, Vector3.new(ray.Position.X, turretcontrols.PivotHandlePart.Position.Y, ray.Position.Z))
			local newcf = cf:ToObjectSpace(turretcontrols.PivotHandlePart.CFrame)
			
			local x,y,z = newcf:ToOrientation()
			
			local finaldegree = math.deg(y)
			
			if finaldegree < -35 and finaldegree > -125 then
				handle:PivotTo(cf)
			end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.