Basically, I am trying to make a boat roll on the waves of an ocean. One method that I think will work the best is by having four ray casts on each side of the boat. Bow, Stern, Starboard, and Portside. I already have the math figured out for the orientation and position of the boat, but the problem I have is that the raycasts arenât actually picking up waves and are instead picking up the original position of the ocean plane.
(The ocean is a meshpart that has its bones updated to create the âwavesâ)
The local script is in the player since the waves are also generated locally.
local RunService = game:GetService("RunService")
local Stern = game.Workspace.Boat.Stern
local Bow = game.Workspace.Boat.Bow
local wavelist = game.Workspace.Ocean.Oceans:GetDescendants()
RunService.Heartbeat:Connect(function(step)
local sternray = Ray.new(Stern.Position, Vector3.new(0, -100, 0))
local bowray = Ray.new(Bow.Position, Vector3.new(0, -100, 0))
local wavefound1, position1 = workspace:FindPartOnRayWithWhitelist(sternray, wavelist)
local wavefound2, position2 = workspace:FindPartOnRayWithWhitelist(bowray, wavelist)
-- Code shows the position of the raycast as a part, all come back as the original plane position before the waves were ever generated.
if wavefound1 then
local Newpart = Instance.new("Part")
Newpart.Parent = game.Workspace
Newpart.Anchored = true
Newpart.Position = position1
wait(0.1)
Newpart:Destroy()
end
end)
If you have any solutions or ideas to solve this problem that would be awesome! Thank you!
To my knowledge, the mesh part reacts as one whole part, as the bones donât count towards separate parts. This means that when youâre casting your rays, technically it isnât a syntax error, but itâs more of a logical error.
I have a few suggestions to fix this, however. First, cast multiple rays at several heights to determine once the boat is within contact of the ocean, and then cast right above that. A problem that may come out of this, however, is that the boat would work on land, so youâd have to set up some sort of counter-measure towards this.
In a second but not so helpful solution, youâd have to redesign the ocean, with multiple parts instead, as that way youâll be able to cast the rays in the way that you are now.
Iâd also like to say that the waves should probably be done on the server, as if the boats position/ rotation is based off of the waves, the boat would have to be done client sided as well, making it exploitable. The player could also alter the waves.
Thank you for that suggestion, I took that and basically made it so a part would match the position of the bone so the ray cast hits the part not the bone. The downside to this, however, is that each ocean plane has 5000 bones and with 9 planes thatâs a lot of parts.
Anyways, I did this and well it worked! Unfortunately, now the ship wonât move because vehicle seat is not working on Robloxâs end.
Just a suggestion here, but if you can get the nearest bone to each edge of the ship you can use that as a height reference. From there you could use a trilinear interpolation algorithm to get the height, or maybe a simple OLS regression to get the mean ship height on the water and increase or decrease the edges accordingly. Could also use a vector force to push upto the nearest bone maybe. Just some ideas