lua - 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
解决方案
It could be that your logic is fighting with itself. You are checking that you are underwater for each block, and if one says yes, but the next says no, you will essentially be undoing any changes that should be happening.
So one fix might be to ask all of the water blocks, "am I underwater?" And if any say yes, then change the lighting and reverb, but if ALL of them say no, then change it back.
-- 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)
推荐阅读
- flutter - Flutter DataTable 截断文本
- pandas - pandas 数据框按列分组并根据计数单独更新另一列行
- reactjs - 使用 Jest 和 Enzyme 测试 useLayoutEffect 以调整窗口大小
- c - 使用 eclipsec.exe 编译失败,但使用它通过的 IDE
- dialogflow-es - 如何在 Dialogflow 中添加可点击的邮件地址
- intellij-idea - 有没有办法为 IntelliJ-idea 中的特定检查配置不同的突出显示颜色?
- xml - PowerShell 点引用 XML 属性
- visual-studio-2019 - 如何使用 XInput 在 VS19、.Net Core 3 的终端上打印左操纵杆 Xbox Once 控制器?
- angular-cli - 我们运行 ng build --prod 时默认设置的选项是什么
- version-control - 在多个项目中与 Azure 板共享相同的私有 Azure DevOps 存储库