I am trying to make a script so the player dashes when they press Q, this works just how I want it, exept when you jump and then dash you fall, i want to make the player not fall until the dash is complete.
local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
local uis = game:GetService("UserInputService")
local i = 0
local anims = {script.Dash1,script.Dash2}
local cooldown = false
local cooldowntime = 0.7
uis.InputBegan:Connect(function(key)
if not cooldown then
if key.KeyCode == Enum.KeyCode.Q then
cooldown = true
i = 1-i
local playAnim = humanoid:LoadAnimation(anims[1+i])
playAnim:Play()
script.Sound:Play()
if humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 200
else
player.Character.HumanoidRootPart.Velocity = player.Character.HumanoidRootPart.CFrame.lookVector * 130
end
wait(cooldowntime)
cooldown = false
end
end
end)
(please ignore my bad code, this is what worked so i did it)
Are you sure you aren’t anchoring your whole character at this point? I am pretty sure your animation should keep playing if you only anchor the HumanoidRootPart. Maybe I could be wrong though. I never used R6 before.
You can use a Align Position to lock the player to a position only on the Y-axis to stop them from falling while still moving.
-- Assumes 'hrp' is character's HumanoidRootPart
local attach = Instance.new("Attachment", hrp)
local alignPos = Instance.new("AlignPosition", hrp)
alignPos.Enabled = false -- Disabled on start
alignPos.Responsiveness = 50 -- set to your preference
alignPos.ApplyAtCenterOfMass = true
alignPos.ForceLimitMode = Enum.ForceLimitMode.PerAxis
alignPos.MaxAxesForce = Vector3.new(0, math.huge, 0) -- Only apply force on Y axis
alignPos.Mode = Enum.PositionAlignmentMode.OneAttachment
alignPos.Attachment0 = attach
For toggling:
-- Enabling
alignPos.Enabled = true
alignPos.Position = hrp.Position -- Update to current position
-- Disabling
alignPos.Enabled = false
Instead of directly setting the players velocity on the root part I would recommend using a body velocity or vector force to achieve the result you want. Even though body velocity is deprecated if you set the max force on the y-axis to something high and move the player with it they will not be affected by gravity until the force is removed.