So I’ve been working on this slide script, which in it you can cancel the slide by jumping, and so it feels better I made it so it carries a bit of the momentum (really it’s just using another vectorforce thing but still)
But I’ve ran into the problem where it just stops in midair like shown in the video below:
I’ve figured out that it’s because the way I calculate how much distance the player should travel is through a lookVector multiplied i.e “lookVector * 40” which only calculates how far you travel in a direction but doesn’t end on the ground.
So my problem is that I’m unsure how to tell the script to end the arc once it lands on the ground.
-- -- variables and get service
local UIS = game:GetService("UserInputService")
local keybind = Enum.KeyCode.LeftShift
local Cancel = Enum.KeyCode.Space
local canslide = true
local player = game:GetService('Players').LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local HumanoidRootPart = char:WaitForChild('HumanoidRootPart')
local Humanoid = char:FindFirstChild("Humanoid")
local loop = true
-- animation stuff
local SlideAnim = Instance.new("Animation")
SlideAnim.AnimationId = "rbxassetid://14431552792"
-- sound stuff
local RunSound = HumanoidRootPart:WaitForChild("Running", 10)
local JumpSound = HumanoidRootPart:WaitForChild("Jumping", 10)
local slideSound = Instance.new("Sound")
slideSound.SoundId = "rbxassetid://14433837493"
slideSound.Parent = char.HumanoidRootPart
slideSound.Volume = 0.1
local playAnim = Humanoid:LoadAnimation(SlideAnim)
UIS.InputBegan:Connect(function(input,gameProcessed)
if gameProcessed then return end
if not canslide then return end
if input.KeyCode == keybind then
if freefall == true then -- dashes if in the air
canslide = false
print("You have dashed")
local dash = Instance.new("BodyVelocity")
dash.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
dash.Velocity = char.HumanoidRootPart.CFrame.lookVector * 80
dash.Parent = char.HumanoidRootPart
wait(0.3)
dash:Destroy() -- destroys instance once finished
wait(0.3)
canslide = true
else -- slides if on ground
canslide = false
print("You have slided")
playAnim:Play()
RunSound.Volume = 0 -- disables running sound
slideSound:Play()
char.HumanoidRootPart.CanCollide = false
local slide = Instance.new("BodyVelocity") -- creates a body velocity
slide.MaxForce = Vector3.new(math.huge,0,math.huge)
slide.Velocity = char.HumanoidRootPart.CFrame.lookVector * 60
slide.Parent = char.HumanoidRootPart
for count = 1, 6 do
if Humanoid.Jump == true then
local position1 = HumanoidRootPart.CFrame.lookVector
local position2 = HumanoidRootPart.CFrame.lookVector * 1
local duration = 0.1
local direction = position2 + position1
local force = direction / duration + Vector3.new(0, workspace.Gravity * duration * 0.5, 0)
char.HumanoidRootPart.CanCollide = true
HumanoidRootPart:ApplyImpulse(force * HumanoidRootPart.AssemblyMass)
RunSound.Volume = 1
playAnim:Stop()
slideSound:Stop()
slide:Destroy()
wait(0.5)
canslide = true
end
wait(0.1)
slide.velocity *= 0.7
end
char.HumanoidRootPart.CanCollide = true
RunSound.Volume = 1
playAnim:Stop()
slide:Destroy()
wait(0.2)
canslide = true
end
end
end)
while loop == true do wait(0.01) -- detects if the player is in the air or on the ground.
if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
freefall = true
else
freefall = false
end
end