I’m making an idle turret of sorts, anyways, it’s cosmetic and supposed to be simple. My problem lies with tweening and probably the calculation or the application. It’s supposed to rotate, and elevate, then rotate, etc. Which works, but as soon as it rotates after it elevates to a degree higher/lower than 0, the ‘elevationPart’, the higher one, tilts to its sides, adjusting it’s Z axis, causing the barrels to be in an awkward position.
I tried manipulating the orientation directly, using Vector3, though…
If I dont CFrames, it wont tween the welded parts for some reason, unless I’m missing something?
As a side note: I made the elevationPart, rotate with the rotationalPart, so it remains consistent. If there’s a better way to do this better, please feel free to share.
As you can see it’s not behaving like a proper turret:
Relevant Functions:
local function rotateTo(targetRotation)
local targetRotationalCFrame = CFrame.Angles(math.rad(targetRotation), 0, 0)
local targetElevationCFrame = CFrame.Angles(0, math.rad(-targetRotation), 0)
local currentRotationalCFrame = rotationalPart.CFrame
local currentElevationCFrame = elevationPart.CFrame
local newRotationalCFrame = currentRotationalCFrame * targetRotationalCFrame
local newElevationCFrame = currentElevationCFrame * targetElevationCFrame
local tweenRotational = tweenService:Create(
rotationalPart,
TweenInfo.new(
SPEED,
EASING_STYLE,
Enum.EasingDirection.InOut
),
{
CFrame = newRotationalCFrame
}
)
local tweenElevation = tweenService:Create(
elevationPart,
TweenInfo.new(
SPEED,
EASING_STYLE,
Enum.EasingDirection.InOut
),
{
CFrame = newElevationCFrame
}
)
print('rotating')
tweenRotational:Play()
tweenElevation:Play()
isPlaying = true
return tweenRotational
end
local function elevateTo(targetElevation)
local tweenAlpha = tweenService:Create(
elevationPart,
TweenInfo.new(
SPEED,
EASING_STYLE,
Enum.EasingDirection.InOut
),
{
CFrame = elevationPart.CFrame * CFrame.Angles(math.rad(targetElevation), 0, 0)
}
)
print('elevating')
tweenAlpha:Play()
isPlaying = true
return tweenAlpha
end
They play after each other completes, eg. Rotate → Elevate → Rotate → etc.
If there are other methods that may be better than what I’m trying to do here, please feel free to share.
P.S. I’ll be gone for a while, so I might not reply sooner.