Ok, so here is my full Skydive system currently (might convert this to a module later to make it a more clear to read):
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local RootAttachment = HumanoidRootPart:WaitForChild("RootAttachment")
local diveSpeed = 30
local defaultJumpPower = 50
local appliedImpulse = math.floor(HumanoidRootPart.AssemblyMass / 6)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvents = ReplicatedStorage:FindFirstChild("RemoteEvents")
local Skydive = RemoteEvents:WaitForChild("Skydive")
local Values = ReplicatedStorage:FindFirstChild("Values")
local Booleans = Values:WaitForChild("Booleans")
local Strings = Values:WaitForChild("Strings")
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local Animations = script:WaitForChild("Animations")
local SkydiveAnimation = Animations:WaitForChild("SkydiveAnimation")
local SkydiveAnimationTrack = Humanoid.Animator:LoadAnimation(SkydiveAnimation)
local debounce = false
local LinearVelocity = Instance.new("LinearVelocity")
LinearVelocity.Attachment0 = RootAttachment
LinearVelocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
LinearVelocity.VectorVelocity = Vector3.new(0, 0, 0)
LinearVelocity.MaxAxesForce = Vector3.new(0, math.huge, 0)
LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
LinearVelocity.Enabled = false
LinearVelocity.Parent = HumanoidRootPart
local function Boost(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
LinearVelocity.VectorVelocity = LinearVelocity.VectorVelocity * Vector3.new(0, appliedImpulse, 0)
SkydiveAnimationTrack:Play(0.5)
elseif inputState == Enum.UserInputState.End then
LinearVelocity.VectorVelocity = Vector3.new(0, -diveSpeed, 0) -- resets the impulse applied to the humanoidrootpart.
if SkydiveAnimationTrack.IsPlaying then
SkydiveAnimationTrack:Stop(0.5)
end
end
end
local StateChangedConnection
StateChangedConnection = Humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Freefall then
if Player:GetAttribute("InRound") then -- if the player is currently InRound.
LinearVelocity.VectorVelocity = Vector3.new(0, -diveSpeed, 0)
LinearVelocity.Enabled = true
Humanoid.JumpPower = 0
ContextActionService:BindAction("SpeedBoost", Boost, true, Enum.KeyCode.J, Enum.KeyCode.ButtonY)
ContextActionService:SetTitle("SpeedBoost", "Boost")
ContextActionService:SetPosition("SpeedBoost", UDim2.new(0.2, 0, 0.5, 0))
else
StateChangedConnection:Disconnect()
end
end
end)
Player:GetAttributeChangedSignal("InRound"):Connect(function()
if not Player:GetAttribute("InRound") then -- if the player is not InRound; in the lobby.
LinearVelocity.VectorVelocity = Vector3.new(0, 0, 0)
LinearVelocity.Enabled = false
Humanoid.JumpPower = defaultJumpPower
ContextActionService:UnbindAction("SpeedBoost")
if SkydiveAnimationTrack.IsPlaying then
SkydiveAnimationTrack:Stop(0.5)
end
end
end)
--[[Skydive.OnClientEvent:Connect(function()
Humanoid.StateChanged:Connect(function(oldState, newState)
print("changed")
if newState == Enum.HumanoidStateType.Freefall then
LinearVelocity.VectorVelocity = Vector3.new(0, -diveSpeed, 0)
LinearVelocity.Enabled = true
Humanoid.JumpPower = 0
ContextActionService:BindAction("SpeedBoost", Boost, true, Enum.KeyCode.J, Enum.KeyCode.ButtonY)
ContextActionService:SetTitle("SpeedBoost", "Boost")
ContextActionService:SetPosition("SpeedBoost", UDim2.new(0.2, 0, 0.5, 0))
end
end)
end)--]]
--[[RoundEnded.Changed:Connect(function(newValue)
if newValue == true then
LinearVelocity.VectorVelocity = Vector3.new(0, 0, 0)
LinearVelocity.Enabled = false
Humanoid.JumpPower = defaultJumpPower
ContextActionService:UnbindAction("SpeedBoost")
if SkydiveAnimationTrack.IsPlaying then
SkydiveAnimationTrack:Stop(0.5)
end
end
end)--]]
I need a better name than āSpeedBoostā too lol. Also, what is lerping? It confuses meā¦
Also, if I were to add obstacles to the skydiving, how would this work? because if they kill the player they can just instantly fall to the target.