roblox 上的水下相机效果
underwater camera effects on roblox
我需要调试此代码的帮助,我正在尝试制作一种效果,其中屏幕被染成蓝色,只要相机位于名为“水”的部分内,混响就会设置为浴室,它适用于 1游戏中的水体和其他水体不会导致效果发生,尽管它为游戏中的每个水体打印,我假设它选择工作的是第一个加载的,但我不确定为什么只有那个注册,它检查所有但只有那个部分真正导致它发生
while true do
wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == "water" then
print ("lolhehehhevljl")
local parms = RaycastParams.new()
parms.FilterDescendantsInstances = {v}
parms.FilterType = Enum.RaycastFilterType.Whitelist
local ray = require(game.Workspace.Modules.raymodule).raycast(game.Workspace.CurrentCamera.CFrame.Position, v.Position, parms)
if ray then
game.Lighting.ColorCorrection.TintColor = Color3.new(1, 1, 1)
game.SoundService.AmbientReverb = Enum.ReverbType.NoReverb
else
game.Lighting.ColorCorrection.TintColor = Color3.new(0, 0.65098, 1)
game.SoundService.AmbientReverb = Enum.ReverbType.Bathroom
end
end
end
end
可能是你的逻辑在自相矛盾。您正在检查每个块是否在水下,如果一个说是,但下一个说不,您实际上是在撤消应该发生的任何更改。
因此,一种解决方法可能是询问所有水块,“我在水下吗?”如果有人说是,那就改变灯光和混响,但如果所有人都说不是,那就改回来。
-- local variables
local Modules = game.Workspace.Modules
local raymodule = require(Modules.raymodule)
local TINT_UNDERWATER = Color3.new(0, 0.65098, 1)
local TINT_NORMAL = Color3.new(1, 1, 1)
-- find all of the water parts
local water = {}
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "water" then
table.insert(water, v)
end
end
-- create a filtered list for raycasting
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
raycastParams.FilterDescendantsInstances = water
-- every frame, check if we are underwater
game.RunService.Heartbeat:Connect(function()
local isUnderwater = false
local cameraPos = game.Workspace.CurrentCamera.CFrame.Position
for i, v in ipairs(water) do
local didHit = raymodule.raycast(cameraPos, v.Position, raycastParams)
if not didHit then
isUnderwater = true
end
end
-- update the camera state
if isUnderwater then
game.Lighting.ColorCorrection.TintColor = TINT_UNDERWATER
game.SoundService.AmbientReverb = Enum.ReverbType.Bathroom
else
game.Lighting.ColorCorrection.TintColor = TINT_NORMAL
game.SoundService.AmbientReverb = Enum.ReverbType.NoReverb
end
end)
我需要调试此代码的帮助,我正在尝试制作一种效果,其中屏幕被染成蓝色,只要相机位于名为“水”的部分内,混响就会设置为浴室,它适用于 1游戏中的水体和其他水体不会导致效果发生,尽管它为游戏中的每个水体打印,我假设它选择工作的是第一个加载的,但我不确定为什么只有那个注册,它检查所有但只有那个部分真正导致它发生
while true do
wait(0.1)
for i,v in pairs(game.Workspace:GetChildren()) do
if v.Name == "water" then
print ("lolhehehhevljl")
local parms = RaycastParams.new()
parms.FilterDescendantsInstances = {v}
parms.FilterType = Enum.RaycastFilterType.Whitelist
local ray = require(game.Workspace.Modules.raymodule).raycast(game.Workspace.CurrentCamera.CFrame.Position, v.Position, parms)
if ray then
game.Lighting.ColorCorrection.TintColor = Color3.new(1, 1, 1)
game.SoundService.AmbientReverb = Enum.ReverbType.NoReverb
else
game.Lighting.ColorCorrection.TintColor = Color3.new(0, 0.65098, 1)
game.SoundService.AmbientReverb = Enum.ReverbType.Bathroom
end
end
end
end
可能是你的逻辑在自相矛盾。您正在检查每个块是否在水下,如果一个说是,但下一个说不,您实际上是在撤消应该发生的任何更改。
因此,一种解决方法可能是询问所有水块,“我在水下吗?”如果有人说是,那就改变灯光和混响,但如果所有人都说不是,那就改回来。
-- local variables
local Modules = game.Workspace.Modules
local raymodule = require(Modules.raymodule)
local TINT_UNDERWATER = Color3.new(0, 0.65098, 1)
local TINT_NORMAL = Color3.new(1, 1, 1)
-- find all of the water parts
local water = {}
for i, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "water" then
table.insert(water, v)
end
end
-- create a filtered list for raycasting
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Whitelist
raycastParams.FilterDescendantsInstances = water
-- every frame, check if we are underwater
game.RunService.Heartbeat:Connect(function()
local isUnderwater = false
local cameraPos = game.Workspace.CurrentCamera.CFrame.Position
for i, v in ipairs(water) do
local didHit = raymodule.raycast(cameraPos, v.Position, raycastParams)
if not didHit then
isUnderwater = true
end
end
-- update the camera state
if isUnderwater then
game.Lighting.ColorCorrection.TintColor = TINT_UNDERWATER
game.SoundService.AmbientReverb = Enum.ReverbType.Bathroom
else
game.Lighting.ColorCorrection.TintColor = TINT_NORMAL
game.SoundService.AmbientReverb = Enum.ReverbType.NoReverb
end
end)