I have this turret model, a Flak 88, that I bought from an asset pack last year.
It’s pretty solid, yet, I am having some issues trying to figure out how to rig it so that it pivots in the following ways:
A) it spins around, which I have been able to do with HingeConstraint here
B) its angle will change, via going up and down, kind of like here, but with some limitations
I was thinking of commissioning this out, but I want to be able to figure out how to use constraints confidently so I can do this myself for future updates/games.
I have a similar cannon model that I use in one of my games, but it is a free model that I did not code myself.
It functions similarly to how I want the Flak 88 to move around, as seen here. That being said, this cannon model uses welds to move around, and not constraints - I am pretty certain that for the Flak 88, using constraints is the way to go.
How would I rig the Flak 88 up? What constrains would I use? I am pretty certain that I would need to use AlignPosition and AlignOrientation. And how would I code it so that, when a player is in a vehicle seat, the gun goes up/down, or turns based on the vehicle seat’s steer/throttle? Here’s the code that the cannon from my existing game works:
angle = 0
local RunService = game:GetService("RunService")
RunService.Heartbeat:Connect(function()
if script.Parent.Steer == 1 then
script.Parent.Swiv:play()
script.Parent.Parent.WER.Value.C0 = script.Parent.Parent.WER.Value.C0 * CFrame.fromEulerAnglesXYZ(0,0.01,0)
elseif script.Parent.Steer == -1 then
script.Parent.Swiv:play()
script.Parent.Parent.WER.Value.C0 = script.Parent.Parent.WER.Value.C0 * CFrame.fromEulerAnglesXYZ(0,-0.01,0)
elseif script.Parent.Steer == 0 and script.Parent.Throttle == 0 then
script.Parent.Swiv:pause()
end
if script.Parent.Throttle == 1 and angle < 20 then
script.Parent.Swiv:play()
angle = angle + 1
script.Parent.Parent.WER2.Value.C0 = script.Parent.Parent.WER2.Value.C0 * CFrame.fromEulerAnglesXYZ(-0.01,0,0)
elseif script.Parent.Throttle == -1 and angle > -15 then
script.Parent.Swiv:play()
angle = angle - 1
script.Parent.Parent.WER2.Value.C0 = script.Parent.Parent.WER2.Value.C0 * CFrame.fromEulerAnglesXYZ(0.01,0,0)
end
end)