Need Physics Scripting Help - Possible Bug

Context:

  • I have a terrain flooding system that spawns terrain water into workspace that rises in level over time.
  • There are parts in there that I want to float, that should float normally in terrain water.
  • None of them are anchored or have modified physics, just plastic, but there are also plastic parts that I don’t want to float.
  • I have a script that correctly sorts all of the parts I want to float and it puts them in a table.
  • Due to the nature of this game, it’s not reasonable to modify the physical properties of every part.

Problem:

  • When I spawn the water and it rises, the parts don’t seem to realize they are in water as far as Roblox Physics are concerned.
  • If I swim over and touch one of these parts, it immediately starts to float as it’s supposed to, which I figure is because my touching it has now caused the physics to check and it realizes it’s in water.
  • After a part has been touched, it properly responds and will keep floating with the rising water.
  • If I let the water stand there long enough (sometimes minutes), eventually the parts will float to the top of the water.

What I want to happen:
I want after the terrain is spawned for the parts to recognize and act like they are in water and float with the rising water. Basically, for the physics to respond just as they would if the water was there already and not scripted.

What I’ve Tried:

  1. Testing to confirm if it was the physics, I’ve manually set the density of the part low, to 2, which should definitely make the part float, it does not float.
    Note: In the right corner, you can see, rig of my avatar floats properly from the beginning, but not any parts or unions, which should all be floating.

  2. Testing to confirm whether or not it was the fact that I spawned the water with a script, I used the part with no custom physics and made some water around it in Studio, ran it, and with no problem, the part just floated right to the top of the water like it’s supposed to.

  1. I tried using raycasting so see if I could get the part’s position in respect to the water so that I could nudge it with force under the water, but I couldn’t seem to get the water to detect when it was submerged in water. If I raycast straight down from the part, I can get it to return that there’s terrain water…
	local startPosition = part.Position + Vector3.new(0, part.Size.Y / 2 + offset, 0) -- Position slightly above the top center of the part
	local endPosition = Vector3.new(0, -1000, 0) -- Aimed straight down with a good distance to check.

When I do this, I get the return:

  14:25:45.505  Raycast material value: Enum.Material.Water  -  Server - Terrain Nudge Test:46
  14:25:45.505  Applying nudge...  -  Server - Terrain Nudge Test:64

However, I’ve yet to be able to get it to properly detect the water if I aim the raycast anywhere over the top of the part to see if it is submerged.

  1. I’ve tried to use buoyancy or clone in fictitious floats, but anything that I do like that seems to mess with the parts too much before the water hits them, sometimes even the littlest thing sends things flying long before the water hits.

It’s important to note that the goal is to just get them to behave normally and to have them properly respond to the water when it rises, and not have them behave abnormally or strangely before the water rises.

I’ve got a script that gets all of these parts and puts them in a table.
Now I’m left with this…

for _, part in ipairs(floatingParts) do
-- Everything I do to them seems to fail to fix the issue.
end

Does anyone have any idea what I can do to an object that without messing up the object’s physics sitting there on the ground, might be able to periodically get it to do something to nudge a physics check so it will realize it’s in water and start responding normally?

Any help would be greatly appreciated.

I’m going to post the answer to this just in case this ever helps anyone in the future.
I’m 99% sure this is a bug and should be reported in #bug-reports but I am not one of the privileged ones that can post in there, so if they find it they find it here, great, if not, whatever.

So this bug is pretty dumb, when you spawn terrain somewhere parts don’t seem to notice if the water spawned around them putting them in water.

In theory, if you cframed the part up so it isn’t touching anything, it should re-calculate the physics.
But if you don’t want to or can’t just move the parts like I did, I found a simple solution.

Fiddling around with all the physics server sided while the part was sitting under water, I found 1 single property that made it re-check other than CanCollide that just made it fall through the floor obviously.

CanTouch

For some reason, if you toggle CanTouch, it doesn’t matter if it’s on or off, the part will re-check its physics environment and update.

I set it with some control variables to adjust it so it doesn’t do it more than needed, it only takes 1 toggle either way to make it update and start to float, but literally all I did was:

	local function toggleCanTouch()
		for _, part in ipairs(floatingParts) do
			part.CanTouch = not part.CanTouch
		end
		toggleTimes = toggleTimes + 1
		if toggleTimes < toggleCount then
			wait(toggleFrequency)
			toggleCanTouch()
		end
	end
	toggleCanTouch()

So if any of you ever happen to be scripting terrain water and you want parts to respond to the water physics without having to touch them, move them, or wait however long it takes for Roblox to decide it wants to let them know they’re in water, for now, toggling CanTouch updates the physics and gets everything moving as it should.

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