TurretShooty is unanchored besides the primary part which all parts are welded to
TurretMovey is all anchored including primary part
When turret movey moves so does turret shooty.
I want turretshooty to face the player’s root accordingly to its Y axis.
Heres the aiming part of the script:
-- Face target to then shoot
function FaceTarget()
local CurrentTarget = Targets[1].Character
local CurrentTargetHumanoid = CurrentTarget.Humanoid
if CurrentTargetHumanoid.Health > 0 then
local CharacterPosition = CurrentTarget.PrimaryPart.Position
-- Calculate rotation for TurretMovey
local NewMoveyCFrame = CFrame.lookAt(TurretMovey.PrimaryPart.Position, CharacterPosition - Vector3.new(0, -180, 0))
local TurretMoveyCFrame = CFrame.fromMatrix(TurretMovey.PrimaryPart.Position, TurretMovey.PrimaryPart.CFrame.XVector, NewMoveyCFrame.YVector)
-- Calculate rotation for TurretShooty
TurretMovey:SetPrimaryPartCFrame(TurretMoveyCFrame)
print("Adjusting")
end
end
local TurretShootyPosition = Script.Parent.Position
local LookAtCFrame = CFrame.lookAt(TurretShootyPosition,pos2)
local PitchAngle,_,_ = LookAtCFrame:ToOrientation()
local CFrameResult = CFrame.new(TurretShootyPosition) * CFrame.Angles(PitchAngle,0,0)
If it seems to be reversed then change the PitchAngle in the CFrame.Angles() bit to -PitchAngle. And CFrameResult should be the CFrame you wanted.
local TurretShootyPosition = Script.Parent.Position
local LookAtCFrame = CFrame.lookAt(TurretShootyPosition,pos2)
local PitchAngle,_,_ = LookAtCFrame:ToOrientation()
local CFrameResult = TurretMovey.CFrame * CFrame.Angles(PitchAngle,0,0)