I am creating a Free model Portable Water part that actually lets you swim in it, with even a custom swimming animation and everything. but I need to detect that the camera is colliding with the water part itself to create a underwater effect.
Create a part and set it’s CFrame to the camera CFrame. Weld it, and then use a .Touched event or a Region3 and then use the rest of your code. Be sure to make it’s size something that is appropriate and isn’t too big or too small. Just try to make something that feels good, lots of fine-tuning will probably be needed
As far as my knowledge goes, you can’t access the camera through a server script. You’d need to do it on the client. Don’t worry about server replication, since the effect will only be for the local player
A RenderStepped event might be better for this. You can just continuously set the part’s CFrame to the camera’s CFrame. You should put the local script somewhere inside of the player or player character, such as StarterCharacterScripts or StarterGui because that’s what lets you access most client-sided things.
You could also Raycast using the Camera’s position:
--LocalScript I'm assuming
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local CamPos = Camera.CFrame.Position
local RayDirection = Camera.CFrame.LookVector
RunService.RenderStepped:Connect(function()
local Result = workspace:Raycast(CamPos, RayDirection)
if Result then
print("Camera is intersecting part: "..Result.Instance)
end
end)