I am wanting to have a natural gravity effect with my hoverboard, so instead of just snapping a player to a position, they should gradually glide down
Being fired from a heartbeat event
function HoverboardController:Update(deltaTime)
if not self.Board then return end
local Character = Player.Character
if not Character then return end
Params.FilterDescendantsInstances = {self.Board, Character}
local HighestY = -100000
for _, hoverAttachment in pairs(self.Board:GetChildren()) do
if hoverAttachment.Name ~= "Hover" then continue end
local Raycast = workspace:Raycast(
hoverAttachment.WorldPosition,
hoverAttachment.CFrame.UpVector * -1000,
Params
)
if not Raycast then continue end
if Raycast.Position.Y > HighestY then
HighestY = Raycast.Position.Y
end
end
local Raycast = workspace:Raycast(
self.Board.Position,
self.Board.CFrame.UpVector * -1000,
Params
)
local FrontSpeed = 0
local SideSpeed = 0
if Raycast then
local Force = -K * (self.Board.Position.Y - (HighestY + 1.75)) * self.Board.Mass
if not self.Forward and not self.Backward then -- Not moving
self.Board.BodyGyro.CFrame = CFrame.new(
self.Board.CFrame.Position
) * CFrame.lookAt(
Vector3.new(),
Vector3.new(self.Board.CFrame.LookVector.X, 0, self.Board.CFrame.LookVector.Z)
) * CFrame.Angles(0, self.Rotation, 0)
else
if self.Forward then
FrontSpeed = -100000
elseif self.Backward then
FrontSpeed = 50000
end
local xR, yR, zR = Camera.CFrame:ToOrientation()
local ForwardRotation = Camera.CFrame * CFrame.Angles(-xR, 0, -zR)
self.Board.BodyGyro.CFrame = ForwardRotation * CFrame.Angles(0, math.rad(-90), 0) * CFrame.Angles(0, self.Rotation, 0)
end
local Jump = self.Jump and Vector3.new(0, 10, 0) or Vector3.new(0, 0, 0)
if FrontSpeed ~= 0 then
self.Board.Sound.PitchShiftSoundEffect.Octave = 2
else
self.Board.Sound.PitchShiftSoundEffect.Octave = 1
end
self.Board.BodyForce.Force = (self.Board.CFrame.UpVector * Force) + (self.Board.CFrame.RightVector * FrontSpeed) + (self.Board.CFrame.LookVector * SideSpeed) -- + Jump
else -- No raycast, flatline
self.Board.BodyGyro.CFrame = CFrame.new(
self.Board.CFrame.Position
) * CFrame.lookAt(
Vector3.new(),
Vector3.new(self.Board.CFrame.LookVector.X, 0, self.Board.CFrame.LookVector.Z)
) * CFrame.Angles(0, self.Rotation, 0)
self.Board.Sound.PitchShiftSoundEffect.Octave = 1
end
Character.HumanoidRootPart.Velocity = Vector3.new()
end