I wrote a very simple water “physics” script that checks if a CFrame centered around the character’s torso is touching a water object, and if so, give the character a bodyvelocity (yes, I know it’s deprecated). If it isn’t, remove the bodyvelocity (not shown in this example but not important)
local pos = torso.CFrame
for i,v in (workspace:GetPartBoundsInBox(pos,Vector3.new(1,1,1))) do --Torso touching water, initiate swim
if v.Name == "water" and not table.find(touching,"water") then
table.insert(touching,"water")
end
end
if table.find(touching,"water") then --If torso touching water, swim
if not torso:FindFirstChild("waterPhys") then
local mover = Instance.new("BodyVelocity")
mover.Name = "waterPhys"
mover.maxForce = Vector3.new(0,1e5,0)
mover.P = 1e1
mover.Parent = torso
end
else
if torso:FindFirstChild("waterPhys") then
torso.waterPhys:Destroy()
end
end
Doing this works fine, except that constantly applying and deleting bodyvelocity instances inside of a character when at the surface of the water is bound to create jittery movement with the character, which would be tolerable if the camera didn’t jitter with it.
(The jitter is less noticeable in the video but it’s there!)
Is there a better way to go about doing this to eliminate the jitter?