Flashlight UDP uses EulerAngles instead now

This commit is contained in:
2024-03-02 16:35:12 -05:00
parent b1bde56f5c
commit a3a8720c91
2 changed files with 27 additions and 11 deletions

View File

@@ -86,7 +86,12 @@ function Actions:EnableFlashlight(FlashlightKey: Enum.KeyCode)
task.spawn(function()
while Actions.FlashlightEnabled do
FlashlightRemote:FireServer(table.pack(self.CurrentCamera.CFrame:ToEulerAnglesXYZ()))
--Remotes cant transmit dictionaries
--Note: if dictionaries are more than 1 value, encode it into JSON
local c = table.pack(self.CurrentCamera.CFrame:ToEulerAnglesXYZ())
table.insert(c, c.n)
FlashlightRemote:FireServer(c)
Delta:time()
end
end)

View File

@@ -10,11 +10,10 @@ type FlashlightUDP = RBXScriptConnection
type LocalPlayer = Player
type HumanoidRootPart = BasePart
type EulerXYZ_struct = {
[number | string]: number
}
type EulerXYZ_struct = {number}
Flashlight.Enabled = false
Flashlight.HeadHeight = 1
local CharacterShared = _G.include(script, "CharacterShared")
@@ -24,10 +23,10 @@ Flashlight_UDP.Parent = CharacterShared
local FlashlightUDP_Event: FlashlightUDP?
function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart)
local function FlashlightPart(HumanoidRootPart: HumanoidRootPart): (Part, SpotLight, Sound)
local FlashlightPart = Instance.new("Part") :: Part
FlashlightPart.Size = Vector3.new(.1,.1,.1)
FlashlightPart.CFrame = HumanoidRootPart.CFrame
FlashlightPart.CFrame = HumanoidRootPart.CFrame+Vector3.yAxis
FlashlightPart.CanCollide = false
FlashlightPart.CastShadow = false
FlashlightPart.Anchored = true
@@ -42,21 +41,33 @@ function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: Huma
SpotLight.Enabled = false
SpotLight.Parent = FlashlightPart
FlashlightPart.Parent = HumanoidRootPart
local ToggleSound = Instance.new("Sound") :: Sound
ToggleSound.Name = "Flashlight"
ToggleSound.SoundId = "rbxassetid://16454678462"
ToggleSound.Volume = .5
ToggleSound.Parent = HumanoidRootPart
FlashlightPart.Parent = HumanoidRootPart
return FlashlightPart, SpotLight, ToggleSound
end
function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart)
local FlashlightPart, SpotLight, ToggleSound = FlashlightPart(HumanoidRootPart)
if FlashlightUDP_Event then
warn("[Server Flashlight]: UDP event was already created, duplicating...", debug.traceback())
end
FlashlightUDP_Event = Flashlight_UDP.OnServerEvent:Connect(function(Messenger: Player, CameraEuler: EulerXYZ_struct)
if Messenger.UserId == LocalPlayer.UserId then
-- FlashlightPart.CFrame = CameraCFrame
-- print((HumanoidRootPart.Position-CameraCFrame.Position).Magnitude)
--The compiler/optimization level should inline this
local ExtraCheck = CameraEuler[4] and CameraEuler[4] == 3
if Messenger.UserId == LocalPlayer.UserId and ExtraCheck then
local RootPartCFrame = HumanoidRootPart.CFrame
FlashlightPart.CFrame = CFrame.new(
RootPartCFrame.X,
RootPartCFrame.Y+Flashlight.HeadHeight,
RootPartCFrame.Z)*CFrame.Angles(CameraEuler[1],CameraEuler[2],CameraEuler[3])
end
end)