Need help scripting a skydive system

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.

Lerping just returns a value in-between two values. For example, lerping in 1D looks like this:

local function lerp1D(one, two, alpha)
    return one * (1 - alpha) + two * alpha
end

This returns a value thatā€™s alpha*100 percent between one and two.

Itā€™s used for smoothly moving between values.


This is up to you. If youā€™re worried about the parts falling, make sure to add a check for the target to make sure the player is alive.

You could do lots of things for obstacles:

  • The player losses when they hit a obstacle
  • The player gets a parachute that slows them down to 0 fall speed until they arenā€™t above the obstacle anymore
  • The player exits skydiving and must walk/run off the obstacle, and it takes a bit to regain their speed
  • etc
1 Like

What I could do is have the player bounce back upwards, when they get hit by an obstacle that has that specific ā€˜attributeā€™.

1 Like

That would be cool!

1 Like