Preventing boat driving on land

Hiya. I made a fairly simple boat using body velocity, gyro and position and it works perfectly in water but the issue arrises when I drive it onto land. It moves about on land easily. I saw a previous topic about this, taking about editing the body position, but found the explanation hard to understand. Would anybody be able to explain how I would tackle this issue? I’ll link a video of how the boat behaves at the moment.

https://imgur.com/a/z4wSmeC

You could detect if the parts are in water, and halt the boat’s movement ability or slow it down gradually when it stops being in water and hits land, this post may help you, it’s for detecting when a player is in water but the same logic should apply to parts. Here

Great, thanks. Whilst waiting for a reply I had an idea and it works but I’ll just run it by you to check if you think it’s an ok way to do it. I put a value inside each piece of shore and then inside the boat there’s a touched event and if the thing that’s touched contains that value, the boat slows down. Does that sound alright?

It sounds very tedious. Though it would work, just very complicated. does the solution in the post that i mentioned not work for you?
It would be much better than having to account for every piece of shore.

oh yeah now you say that it does seem tedious. Just not super confident with ray casting/region 3. Could learn though.

You could cast raycasts from a few sides of the boat, and if it hits anything that isn’t registered as water, the boat will slow down or stop. Raycasting isn’t actually that complicated, you just create the raycast, give it a start point and direction, then collect the result after. Here’s an example of a simple raycasting script if it helps:

local RayStartingPoint = workspace.Part.Position -- or it could be a Vector3 position, like Vector3.new(0,2,0) 
local RayDirection = workspace.Part.Position + Vector3.new(0,2,0) -- this would be the position of a part, but 2 studs up in the air
local RaycastParameters = RaycastParams.new() -- raycastparams is an extra thing that you can use to edit your raycast

local RaycastResult = workspace:Raycast(RayStartingPoint, RayDirection, RaycastParameters)
if RaycastResult then -- if the ray hit anything then proceed
local RaycastInstance = Raycast.Instance -- the part that the raycast could have hit
if RaycastInstance then
print(RaycastInstance.Name.." was hit!")
end
end

Above is a simple raycast script that’s pretty much the bare basics of raycasting. Give ray start point and way for ray to go and ray will go pew, basically.
There is also the old raycast system that’s basically the code above but without raycastparams.
It’s pretty much the same as the new system (the code above):

local RayStartPoint = workspace.Part.Position
local RayDirection = workspace.Part.CFrame.LookVector -- LookVector is a Vector3 value that tells you where the part is facing.
local PartRay = Ray.new(RayStartPoint,RayDirection)
local HitResult, HitPosition = workspace:FindPartOnRay(PartRay, workspace.Part) -- HitResult would be the part that the ray hit and HitPosition would be the exact point the ray and the part collided
if HitResult then -- if the ray actually hit anything and that HitResult isn't just air
print(HitResult.Name.." was hit!")
end

That’s pretty much all there is to Raycasting, but you can find extra details on RaycastParams and such on the DevHub page here.

1 Like

Oh wow thank you so much, this will really help me.

1 Like

You’re welcome! Glad that i was able to help.