How would I go about making this boat tilt in the water?

I took a free model ship and put it into a world with a mesh formed water script and I wish to figure out a way to make it tilt with the waves to make it look like its following the waves. I made a part called Center Of Mass (COM) and I’ve welded the ship to it. I place a bodyposition there that keeps it bobbing between the two closest points and it works well, however when I try using bodygyros to tilt it with the water, no method i’ve tried makes it look even remotely good.

Picture of the ship (i highlighted the COM part.)

Maybe use another invisible block welded to the end you want to tilt and custom change the mass to lean the right amount. A “counter weight”

I deform the water using bones. I want to make it tilt based on bone’s pos. I don’t know how I’d do this though. At least fluently.

How about 2 ‘Mass’ Parts, one at either end, with BodyPositions in both?
Could you change the BodyPosition of both of them depending on the Position of the Bones? I’m not familiar with Bones of a Mesh so I don’t know if there is a readable Position of Bones.

I’ve tried this, but what happens is, the boat turned to face one direction, and it spins a little, then it goes crazy and picks positions that are “close” relatively to face, but not near where it originally was, and it causes the boat to spin REALLY fast. And yes, bones have 2 positions, “Position” which is it’s position to the center point of the mesh like an attachment, and a “WorldPosition” which is y’know, the world position. xd

Did you still have a BodyGyro in the boat to keep it from spinning?

I’m using the bodygyro to turn it. My code right now is it takes the two positions closest to the bow and stern of the ship using mass parts as suggested, then I send both points, and make the ship look from the stern to the bow, and it starts spinning for some reason even though its in a straight line? I have 0 clue.

“and make the ship look from the stern to the bow”
Do you mean you have the Part in the stern try to face the Part in the bow?
So if the Part in the bow moves the stern Part has some sort of action working on it to try to keep facing the bow Part?
That sounds like the reason you’re spinning the boat, it can’t stay stable trying to chase a moving Part.

Steal from unity the boat tilt is caused by the how much the ship is submerged in the water, the language and method to add the force may be different but the math stays the same:

1 Like

I loop through all bones and take the closest bones to the stern and the bow and make the center part gyro turn from the stern point to the bow point

I shall watch this video, I hope I can gain something from it, I usually flop on these types of mathy vids.

That’s the issue. When the boat rotates the gyro keeps trying to turn to update its rotation, which is never solved since the bow Part is moving.

How would I do this then? If it’s going to spin based off the 2 points how would I give the rotation correctly?

Set the Gyro Rotation once, but don’t change it in a looped script, only change it when there is Player input.

What do you mean by this? Because if the player isn’t on the boat, it won’t tilt with the water.

You can mimic buoyancy physics with BodyGyro and BodyPosition, but the cleanest way of doing this is by implementing buoyancy physics like @dthecoolest mentioned with actual forces.

I tried using the unity video’s method, but how would I go about that? I attempted bodyforces but roblox doesn’t have it apply on each axis, it applies on the whole rig.

Don’t wanna bump this but I spent like a year and a half looking for the solution and I finally found this if anyone else wants a definitive answer.

Using a formula posted by @robro786 in his post about sampling terrain water height.

I use a function to get two points sample position, then their wave positions, then I send it to this formula that robro also posted with the solution.

image

Written in code if anyone doesn’t want to write it themselves:

function getRotAngle(pos1,wavePos1,pos2,wavePos2)
	local h = wavePos1.Y-wavePos2.Y
	local b = (pos1-pos2).Magnitude

	local angle = math.atan(h/b)

	return angle
end

Calculate for stern to bow, and port to starboard for pitch/roll respectively and this will roll your boat fluently, it’s been a long journey but finally I was able to make boats work with mesh water. X_X

as a note for anyone in the future trying to solve this, don’t revive this dead thread, just PM me on the dev forums, I’ll respond when I get the chance to anyone.

4 Likes