Fix jittery movement with bodyvelocity

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?

Instead of constantly removing and creating a bodyVelocity, try changing its velocity(P) to zero instead of destroying it and when it would be time to make a new one make a section that checks if you already have one or not, so that you don’t have many of them, and then make the velocity of the existing bv your original number

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.