I am trying to create a hover vehicle, using a mix of physics and raycasting
The 2 nodes I am using to check the hover height are not updating correctly, even though the code is the EXACT same.
https://gyazo.com/4cf22969d0b9e6f45982990753b171f7
I have tried separating them into different functions, adding a print(which sometimes made it work),
and I cant do much else, I know my raycast function is working correctly because I added a debug part that appears at the Result.Position
--/Constants\--
local plr = game.Players.LocalPlayer
local char = plr.Character
local Svalue = script:FindFirstChild('Speeder').Value
local Engine = Svalue:FindFirstChild('Engine')
local Seat = Svalue:FindFirstChild('VehicleSeat')
local RayParts = Engine:FindFirstChild('RayParts')
local pars = RaycastParams.new()
pars.FilterType = Enum.RaycastFilterType.Blacklist
pars.IgnoreWater = false
pars.FilterDescendantsInstances = {char}
--/Functions\--
local function DebugPart(results)
local f =Instance.new('Part')
f.Size = Vector3.new(0.5,0.5,0.5)
f.BrickColor = BrickColor.new('Cyan')
f.Position = results.Position
f.Anchored = true
f.CanCollide = false
f.Parent = Engine
end
local function GetPitch(Part)
local results = workspace:Raycast(Part.Position, Part.CFrame.UpVector * -10, pars)
local current = Part.Position
if results then
DebugPart(results)
local hitmag = Part.Position.Y - results.Position.Y
if hitmag > Engine.HoverHight.Value + 0.2 then
local newpos = current - Vector3.new(0, 0.2, 0)
Part.BP.Position = newpos
elseif hitmag < Engine.HoverHight.Value - 0.2 then
local newpos = current + Vector3.new(0, 0.2, 0)
Part.BP.Position = newpos
end
else
local newpos = current - Vector3.new(0, 0.2, 0)
Part.BP.Position = newpos
end
end
while game:GetService('RunService').Stepped:Wait() do
GetPitch(RayParts.Back)
GetPitch(RayParts.Front)
end
I am completely stuck and do not know what is causing the issue or how to fix it!