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.
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
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:
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.
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.
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.