G’Day Everyone
I’m making a hoverboard using Raycast and want it to work on water terrain as well as “normal terrain” and parts. It works perfect on “Normal Terrain” and parts but seems to be completely ignoring water terrain and the hoverboard doesn’t stay on top of the water terrain.
This is my first time using Raycast so not exactly sure what I’m doing wrong or have overlooked.
I have the ignore water property set to false and have tried to find a solution on here and the Dev Hub. Have placed the Raycast code below if any more or other code is needed to help please let me know.
if CurrentHoverboard then
local RayStart = CurrentHoverboard.Position
local RayDirection = -CurrentHoverboard.CFrame.UpVector * 1000
local RaycastParams = RaycastParams.new()
RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist
RaycastParams.FilterDescendantsInstances = {CurrentHoverboard}
RaycastParams.IgnoreWater = false
local RaycastResult = workspace:Raycast(RayStart, RayDirection, RaycastParams)
if RaycastResult then
local Ground = RaycastResult.Position.Y + (RaycastResult.Position.Y / 2)
CurrentHoverboard.BodyPosition.Position = Vector3.new(CurrentHoverboard.Position.X, Ground + 1.5, CurrentHoverboard.Position.Z) + (CurrentHoverboard.CFrame.RightVector * movement)
CurrentHoverboard.BodyGyro.CFrame = CurrentHoverboard.CFrame * CFrame.Angles(0, rotation, 0)
script.Parent.HumanoidRootPart.Velocity = Vector3.new()
end
end
end)
Just tried your idea and placed a part across the top of the water terrain and the hoverboard still sinks through the part then the water, which makes me think there might be a problem with my code. Ill have another try and look at my code later when I get some more time.
Cheers for the suggestion
Rewrote the code and now the hoverboard successfully hovers over all terrain and parts but now the character does a falling animation only when hovering over water terrain so will try to find a fix and start a new post if I cant find or figure out a solution.
cheers for the help Znimator
posting the the new code below in case it can help someone else who stumbles across this post
game:GetService("RunService").Heartbeat:Connect(function()
if currentHoverboard then
local rayOrigin = currentHoverboard.Position
local rayDirection = Vector3.new(0, -100, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {currentHoverboard}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = false
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Position.Y
currentHoverboard.BodyPosition.Position = Vector3.new(currentHoverboard.Position.X, hitPart + 1.5, currentHoverboard.Position.Z) + (currentHoverboard.CFrame.RightVector * movement)
currentHoverboard.BodyGyro.CFrame = currentHoverboard.CFrame * CFrame.Angles(0, rotation, 0)
script.Parent.HumanoidRootPart.Velocity = Vector3.new()
end
end
end)