How to move turret cannon up and down?

Im currently working on a tank game and i can move the turret right and left but not up and down, can anybody help?

The movement code currently

if Turret.TurretSeat.Steer == 1 then
			Turret:PivotTo(Turret:GetPivot() * CFrame.Angles(0, -math.rad(1), 0))
		elseif Turret.TurretSeat.Steer == -1 then
			Turret:PivotTo(Turret:GetPivot() * CFrame.Angles(0, math.rad(1), 0))
		end
		if Turret.TurretSeat.Throttle == 1 then
			-- idk what to put here
		elseif Turret.TurretSeat.Throttle == -1 then
			-- idk what to put here
		end
1 Like

Repeat the Pivot function however replace the math.rad(1) at X position rather than Y. And make Y: 0.

i tried that, but it didnt move, maybe its because of the welds in the turret?

How about the Z axis? Any difference?

Nope, still does not move, char limit

Wait I’m a bit off could you show an image of tank and what part of it you want to move?

Make sure your model has a PrimaryPart set or else your pivot will not update automatically and behave correctly.

i want the green part to move

He is using PivotTo not SetPrimaryPartCFrame. You don’t need a Primary part to use PivotTo

Could you show the structure of the tank from Explorer? And what are you referring in the script as Turret?

grafik

The whole script currently, the Barrel is what i want to move

local RunService = game:GetService("RunService")
local Turret = script.Parent.Turret
local Hull = script.Parent.Hull
local Gun = Turret.Gun.Barrel

coroutine.resume(coroutine.create(function()
	RunService.Heartbeat:Connect(function()	
		if Turret:FindFirstChild("TurretSeat") then
			if Turret.TurretSeat.Steer == 1 then
				Turret:PivotTo(Turret:GetPivot() * CFrame.Angles(0, -math.rad(1), 0))
			elseif Turret.TurretSeat.Steer == -1 then
				Turret:PivotTo(Turret:GetPivot() * CFrame.Angles(0, math.rad(1), 0))
			end
			if Turret.TurretSeat.Throttle == 1 then
				Gun:PivotTo(Gun:GetPivot() * CFrame.Angles(-math.rad(1), 0, 0))
			elseif Turret.TurretSeat.Throttle == -1 then
				Gun:PivotTo(Gun:GetPivot() * CFrame.Angles(math.rad(1), 0, 0))
			end
		end
	end)	
end))

Yes he does, some other person ran into a problem similar to this one while using pivot, I was also not aware of it, here’s my post explaining it.

well i set the PrimaryPart but it still doesnt move

Told you.
Check the docs that pivotto is not related with PrimaryPart at all.

Also @Happygamer1983 you can use corountine.wrap which creates and starts a new thread. It’s much less text to write.

the turret movement doesnt work at all with coroutine.wrap()

That happens if you forget the brackets at the end. What I mean is:

coroutine.wrap(function()
end)()

Why are you using a coroutine? You’re just connecting an event.

I guess he wants to cause the script might be bigger.
Oh NVM ye @mniao is right. That’s an event why are you using coroutine?

Scripts still continue after connecting an event so that’s why I’m asking.

local runService = game:GetService("RunService")

runService.Heartbeat:Connect(function()
	print("heartbeat")
end)

print("do other stuff")

the coroutine is a left over from testing code, removed it