hello could anybody could explain how to detect if the camera touch ha certain part?
im new at scripting so i cant script much =(
Thx in Advance
hello could anybody could explain how to detect if the camera touch ha certain part?
im new at scripting so i cant script much =(
Thx in Advance
Could you elaborate? I don’t quite understand what you’re implying by “touch a part”.
example:
ive created a part and called it water then if my camera hit the water it will create a fog and when i stop touching the water it will go back to normal
The camera isn’t a physical object so you can’t detect when the camera touches something. You can, however, check where the camera’s origin is by accessing its CFrame property.
There are a few threads and resources around about checking if the camera is in water, so be sure to search those threads up. You should always search before posting.
Query to help you get started:
https://devforum.roblox.com/search?q=water%20camera%20category%3A55
I suggest you using Region3. It’s a great way I guess.
Sorry for the late reply but you can do this !
local RunService = game:GetService("RunService")
local material
RunService.Heartbeat:Connect(function()
local cameraPos = workspace.CurrentCamera.CFrame.Position + Vector3.new(0,2-workspace.Terrain.WaterWaveSize,0)
local x, y, z = cameraPos.X, cameraPos.Y, cameraPos.Z
local min, max = Vector3.new(x + 0.01, y + 0.01, z + 0.01), Vector3.new(x - 0.01, y - 0.01, z - 0.01)
local region = Region3.new(max, min)
region = region:ExpandToGrid(4)
if region then
local material = workspace.Terrain:ReadVoxels(region, 4)
if material[1][1][1] == Enum.Material.Water then
game.Lighting.Blur.Size = 10
game.Lighting.ColorCorrection.TintColor = Color3.new(0.545098, 0.803922, 1)
else
game.Lighting.Blur.Size = 0
game.Lighting.ColorCorrection.TintColor = Color3.new(1, 1, 1)
end
end
end)
I hope that was helpful !
local runService = game:GetService("RunService")
local radius = 1
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Whitelist
overlapParams.FilterDescendantsInstances = {workspace.WaterPart}
runService.Heartbeat:Connect(function(deltaTime)
local cameraPosition = game.Workspace.CurrentCamera.CFrame.Position
local parts = game.Workspace:GetPartBoundsInRadius(cameraPosition, radius, overlapParams)
if #parts == 0 then return end
print("Touching WaterPart")
end)
Try to create a part that is in the camera cframe every frame
local RunService = game:GetService("RunService")
local Cam = workspace.CurrentCamera
local part = instance.new("Part")
part.Size = vector3.new(3,3,3)
function StablishPartPos()
part.CFrame = Cam.CFrame
end
RunService.RenderStepped:Connect(StablishPartPos)
Make a part at the camera’s position using runservice, then check if that part is hit.
I would do something like making a hitbox part that always follows the camera and use that to detect touching