Working on some turrets but been having issue w the rotation, when the turret itself tilts it doesnt aim properly
excuse the dictionary usage.
local function Aim()
local AimTemp = {}
AimTemp["CurrentCF"] = BS.CFrame
AimTemp["OffSet"] = (Vector3.new(0,TS.CFrame.Position.Y,0) - Vector3.new(0,BS.CFrame.Position.Y,0))
AimTemp["TurretFoward"] = AimTemp["CurrentCF"]:VectorToObjectSpace(Vector3.new(0,0,-1)) -- LookVector
AimTemp["TurretUp"] = AimTemp["CurrentCF"]:VectorToObjectSpace(Vector3.new(0,1,0)) -- UpVector
AimTemp["LookAtDirection"] = (ST.Position - AimTemp["CurrentCF"].Position).Unit --NewLookVector
AimTemp["DotProduct"] = AimTemp["TurretUp"]:Dot(AimTemp["LookAtDirection"]) -- Decides if its +/- on Up/Down from a value from -1 to 1
AimTemp["Up/DownAngle"] = math.deg(math.asin(AimTemp["DotProduct"])) -- Uses that value from -1 to 1, to make a angle
AimTemp["DotProduct"] = AimTemp["TurretFoward"]:Dot(AimTemp["LookAtDirection"]) -- Decides if its +/- on Up Left/Right from a value from -1 to 1
AimTemp["CrossProduct"] = AimTemp["TurretFoward"]:Cross(AimTemp["LookAtDirection"]) -- Gets The direction the turret will be facing
AimTemp["Left/RightAngle"] = math.deg(math.atan2(AimTemp["CrossProduct"].Y,AimTemp["DotProduct"]))
BS.Orientation = BS.Orientation + Vector3.new(0,AimTemp["Left/RightAngle"],0)
print(AimTemp["Left/RightAngle"])
TS.Orientation = BS.Orientation + Vector3.new(AimTemp["Up/DownAngle"],0,0)
end
ive already tried using object space and pointto but no luck
any help would be appreciated