How to check for weld C0 rotation?

So I’m making a turret system for a game I’m making. I want you to be able to with WASD to turn the turret around. The main issue is that This rotation vertical isn’t limited, meaning you can do whole 360s with the tanks barrel. I only want the turret to go 45 degrees. How do I do this?

Show us your script so we can better understand what we are dealing with.
I’d use something like a Motor6D that has a DesiredAngle and CurrentAngle or you can use Motor6D.Transform for CFraming inputs.

Also you can script in a max value for the elevation of the turret. Something like if input = W then your desired angle = 45, if input = S then desired angle = -5

Mouse = game.Players.LocalPlayer:GetMouse()
weld = Obj.Parent.Barrel
weld.C0 *= CFrame.Angles(0, 0, -.01)

Honestly this is the code that I used for making the turret aim downwards. It turns a small degree for every moment of holding down the key.

if game.Players.LocalPlayer.Character then
				Char = game.Players.LocalPlayer.Character
				Obj = Char:FindFirstChild("Seat").Value
				turningbwd = true
				if Obj then
					Obj.Turning:Play()
					repeat
						Mouse = game.Players.LocalPlayer:GetMouse()
						weld = Obj.Parent.Barrel
						weld.C0 *= CFrame.Angles(0, 0, -.01) -- it works!
						Obj.Parent.Turn:FireServer("vert", -.01) -- accurate
						wait()
					until not turningbwd or game.Players:GetPlayerFromCharacter(Obj.Occupant.Parent) ~= game.Players.LocalPlayer
				end
			end
Mouse = game.Players.LocalPlayer:GetMouse()
weld = Obj.Parent.Barrel
   if mouse value is less than your current barrel angle and greater than your minimum angle
      weld.C0 *= CFrame.Angles(0, 0, -.01)
   elseif mouse value is greater than your current barrel angle and less than your maximum angle
      weld.C0 *= CFrame.Angles(0, 0, .01)
   end

I apoligize for my lack of scripting information, I only know the procedure to calculate your movement.

1 Like

Uh the mouse I don’t know why I had there. I didn’t even use it at all

Nevermind, I have found out a way of detecting the turrets rotation! Thank you very much for helping anyway.