#Dash using HumanoidRootPart:ApplyImpulse() trigging twice for some reason

1 messages · Page 1 of 1 (latest)

cunning ether
#

So the problem is that if you time dashing while jumping in the exact moment the player gets the impulse of the air dash and the ground dash. That is what i thought but after printing once the actual code for the ground dash impulse runs and the code for the air dash impulse runs i've only gotten the print for the ground dash which confused me even more. (Please excuse my English as i am not a english speaker and my english is not that good. and if i didn't explain the problem well enough yet and you still want to help i will reexplain)

Here is the code (Please ignore the double confirming of if the debounce is false. i will fix that after i found a solution to my problem)


The Script is located in StarterCharacterScripts.

#

ah

#

i think my code is to long to put in one message

#

i will send it again in smaller ones

#
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer.Character
local DashRF = game:GetService("ReplicatedStorage").RemoteFunctions.DashVFX
local DashRE = game:GetService("ReplicatedStorage").RemoteEvents.DashRemoteEvent
local Humanoid = player:WaitForChild("Humanoid")
local HumRootPart = player:WaitForChild("HumanoidRootPart")
local Debounce = false

local function SetJumpingTo(boolean)
    Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, boolean)
end

local FrontDashAni = script:WaitForChild("FrontDashAni")
local FrontDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(FrontDashAni)
local BackDashAni = script:WaitForChild("BackDashAni")
local BackDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(BackDashAni)
local RightSideDashAni = script:WaitForChild("RightSideDashAni")
local RightSideDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(RightSideDashAni)
local LeftSideDashAni = script:WaitForChild("LeftSideDashAni")
local LeftSideDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(LeftSideDashAni)


local AirForce = 75
local GroundForce = 150
local AirCD = 1
local GroundCD = 0.75
local SideDashCD = 0.60

UIS.InputBegan:Connect(function(Input, IsTyping)
    if Input.KeyCode == Enum.KeyCode.Q and not Debounce then
        SetJumpingTo(false)
        if Debounce == false then
            Debounce = true
            if player:HasTag("ShiftLock") then
                
--------------------------------------------------------------------------------------------------------------------------------------------
#
                
                if player:HasTag("Pressing W") then
                    if player:HasTag("Jumping") then
                        DashRE:FireServer("FrontDash", "Air")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
                        local Mass = HumRootPart.AssemblyMass
                        local Force = AirForce
                        --DashRE:InvokeServer("Air")
                        print("AirDash")
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        FrontDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(AirCD)
                        Debounce = false
                    else
                        DashRE:FireServer("FrontDash")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
                        local Mass = HumRootPart.AssemblyMass
                        local Force = GroundForce
                        --DashRE:InvokeServer("Ground")
                        print("GroundDash")
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        FrontDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(GroundCD)
                        Debounce = false
                    end
                
--------------------------------------------------------------------------------------------------------------------------------------------
#
                    
                elseif player:HasTag("Pressing S") then
                    if player:HasTag("Jumping") then
                        DashRE:FireServer("BackDash", "Air")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
                        local Mass = HumRootPart.AssemblyMass
                        local Force = -AirForce
                        --DashRE:InvokeServer("Air")
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        BackDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(AirCD)
                        Debounce = false
                    else
                        DashRE:FireServer("BackDash")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
                        local Mass = HumRootPart.AssemblyMass
                        local Force = -GroundForce
                        --DashRE:InvokeServer("Ground")
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        BackDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(GroundCD)
                        Debounce = false
                    end
                
--------------------------------------------------------------------------------------------------------------------------------------------
#
                
                elseif player:HasTag("Pressing A") then
                    if player:HasTag("Jumping") then
                        DashRE:FireServer("LeftSideDash", "Air")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = HumRootPart.CFrame.RightVector
                        local Mass = HumRootPart.AssemblyMass
                        local Force = -AirForce
                        --DashRE:InvokeServer("Air")
                        LeftSideDashAniTrack:Play()
                        LeftSideDashAniTrack:AdjustSpeed(0.75)
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        --BackDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(SideDashCD)
                        Debounce = false
                    else
                        DashRE:FireServer("LeftSideDash")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = HumRootPart.CFrame.RightVector
                        local Mass = HumRootPart.AssemblyMass
                        local Force = -GroundForce
                        --DashRE:InvokeServer("Ground")
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        LeftSideDashAniTrack:Play()
                        LeftSideDashAniTrack:AdjustSpeed(0.75)
                        SetJumpingTo(true)
                        task.wait(SideDashCD)
                        Debounce = false
                    end
                    
--------------------------------------------------------------------------------------------------------------------------------------------
#
                    
                elseif player:HasTag("Pressing D") then
                    if player:HasTag("Jumping") then
                        DashRE:FireServer("RightSideDash", "Air")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = HumRootPart.CFrame.RightVector
                        local Mass = HumRootPart.AssemblyMass
                        local Force = AirForce
                        --DashRE:InvokeServer("Air")
                        RightSideDashAniTrack:Play()
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        --BackDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(SideDashCD)
                        Debounce = false
                    else
                        DashRE:FireServer("RightSideDash")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = HumRootPart.CFrame.RightVector
                        local Mass = HumRootPart.AssemblyMass
                        local Force = GroundForce
                        --DashRE:InvokeServer("Ground")
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        RightSideDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(SideDashCD)
                        Debounce = false
                    end
                
--------------------------------------------------------------------------------------------------------------------------------------------
#
                
                else
                    if player:HasTag("Jumping") then
                        DashRE:FireServer("FrontDash", "Air")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
                        local Mass = HumRootPart.AssemblyMass
                        local Force = AirForce
                        --DashRE:InvokeServer("Air")
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        FrontDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(AirCD)
                        Debounce = false
                    else
                        DashRE:FireServer("FrontDash")
                        local LookV = HumRootPart.CFrame.LookVector
                        local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
                        local Mass = HumRootPart.AssemblyMass
                        local Force = GroundForce
                        --DashRE:InvokeServer("Ground")
                        HumRootPart:ApplyImpulse(Direction * Mass * Force)
                        FrontDashAniTrack:Play()
                        SetJumpingTo(true)
                        task.wait(GroundCD)
                        Debounce = false
                    end
                end
            
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
#
            
            else
                if player:HasTag("Jumping") then
                    DashRE:FireServer(true)
                    local LookV = HumRootPart.CFrame.LookVector
                    local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
                    local Mass = HumRootPart.AssemblyMass
                    local Force = AirForce
                    --DashRE:InvokeServer("Air")
                    HumRootPart:ApplyImpulse(Direction * Mass * Force)
                    FrontDashAniTrack:Play()
                    SetJumpingTo(true)
                    task.wait(AirCD)
                    Debounce = false
                else
                    DashRE:FireServer(true)
                    local LookV = HumRootPart.CFrame.LookVector
                    local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
                    local Mass = HumRootPart.AssemblyMass
                    local Force = GroundForce
                    --DashRE:InvokeServer("Ground")
                    HumRootPart:ApplyImpulse(Direction * Mass * Force)
                    FrontDashAniTrack:Play()
                    SetJumpingTo(true)
                    task.wait(GroundCD)
                    Debounce = false
                end
            end
        end
    end
end)
hardy wyvern
#

😭

#

so there's a lot wrong with your code

#

you could probably make it 5 times shorter

#

do you know what a function is

south quartz
#

so do you want it to just to jump dash?

cunning ether
cunning ether
#

but the problem is that the impulse sometimes gets applied twice

cunning ether
cunning ether
#

Because i have been sitting on debugging that script for like a week now (Working roughly a hour or 2 everyday on it) and i'd really like to fix it and make a proper dash system

south quartz
#

The jump dash can just be the player jump then dash and dash just dash

#

Is there an animation you want with it?

cunning ether
cunning ether
cunning ether
#

Thank you for offering your help i'm looking forward to it tomorrow

south quartz
#

this is a Server Script that you would put in ServerScriptService
maker sure you put a DashEvent in the ReplicatedStorage so the two script can call each other,

LocalScript detects when the dash key is pressed and fires a RemoteEvent to the server.

ServerScript:

Plays the "dash" animation from ServerStorage.

Checks if the player is on the ground or in the air.

Moves the player forward the correct distance.

local ServerStorage = game:GetService("ServerStorage")

local dashEvent = ReplicatedStorage:WaitForChild("DashEvent")
local dashAnim = ServerStorage:WaitForChild("dash")

dashEvent.OnServerEvent:Connect(function(player)
    local character = player.Character
    if not character then return end

    local humanoid = character:FindFirstChildOfClass("Humanoid")
    local hrp = character:FindFirstChild("HumanoidRootPart")
    if not humanoid or not hrp then return end

    -- Play dash animation
    local animator = humanoid:FindFirstChildOfClass("Animator")
    if animator then
        local animTrack = animator:LoadAnimation(dashAnim)
        animTrack:Play()
    end

    -- Determine dash distance (jumping = 4 studs, grounded = 5 studs)
    local distance = 5
    if humanoid:GetState() == Enum.HumanoidStateType.Jumping or humanoid:GetState() == Enum.HumanoidStateType.Freefall then
        distance = 4
    end

    -- Move player forward
    local forward = hrp.CFrame.LookVector * distance
    hrp.CFrame = hrp.CFrame + forward
end)```
#

much smaller let me know how it came out

cunning ether
#

And overall the problem i had was with an weird 2nd Impulse not achiving a dash overall.

#
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer.Character
local DashRF = game:GetService("ReplicatedStorage").RemoteFunctions.DashVFX
local DashRE = game:GetService("ReplicatedStorage").RemoteEvents.DashRemoteEvent
local Humanoid = player:WaitForChild("Humanoid")
local HumRootPart = player:WaitForChild("HumanoidRootPart")
local Debounce = false

local FrontDashAni = script:WaitForChild("FrontDashAni")
local FrontDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(FrontDashAni)
local BackDashAni = script:WaitForChild("BackDashAni")
local BackDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(BackDashAni)
local RightSideDashAni = script:WaitForChild("RightSideDashAni")
local RightSideDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(RightSideDashAni)
local LeftSideDashAni = script:WaitForChild("LeftSideDashAni")
local LeftSideDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(LeftSideDashAni)


local AirForce = 75
local GroundForce = 150
local AirCD = 1
local GroundCD = 0.75
local SideDashCD = 0.60



local function SetJumpingTo(boolean)
    Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, boolean)
end
#

wait

#

huh

#

Discord is beeing funky i'll resent the code from the beginnning again

#
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer.Character
local DashRF = game:GetService("ReplicatedStorage").RemoteFunctions.DashVFX
local DashRE = game:GetService("ReplicatedStorage").RemoteEvents.DashRemoteEvent
local Humanoid = player:WaitForChild("Humanoid")
local HumRootPart = player:WaitForChild("HumanoidRootPart")
local Debounce = false

local FrontDashAni = script:WaitForChild("FrontDashAni")
local FrontDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(FrontDashAni)
local BackDashAni = script:WaitForChild("BackDashAni")
local BackDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(BackDashAni)
local RightSideDashAni = script:WaitForChild("RightSideDashAni")
local RightSideDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(RightSideDashAni)
local LeftSideDashAni = script:WaitForChild("LeftSideDashAni")
local LeftSideDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(LeftSideDashAni)


local AirForce = 75
local GroundForce = 150
local AirCD = 1
local GroundCD = 0.75
local SideDashCD = 0.60



local function SetJumpingTo(boolean)
    Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, boolean)
end
#

what do you get my messages?

#
local function Calculate(LookVector, Boolean, State)
    if LookVector == true then
        local LookV = HumRootPart.CFrame.LookVector
        local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
        local Mass = HumRootPart.AssemblyMass
        local Force = 0
        if Boolean == true then
            if State == "Ground" then
                Force = GroundForce
            end
            if State == "Air" then
                Force = AirForce
            end
        end
        if Boolean == false then
            if State == "Ground" then
                Force = -GroundForce
            end
            if State == "Air" then
                Force = -AirForce
            end
        end
        return Direction, Mass, Force
    else
        local Direction = HumRootPart.CFrame.RightVector
        local Mass = HumRootPart.AssemblyMass
        local Force = 0
        if Boolean == true then
            if State == "Ground" then
                Force = GroundForce
            end
            if State == "Air" then
                Force = AirForce
            end
        end
        if Boolean == false then
            if State == "Ground" then
                Force = -GroundForce
            end
            if State == "Air" then
                Force = -AirForce
            end
        end
        return Direction, Mass, Force
    end
end

local function EndOfDashFunction(AnimationType, CDType)
    AnimationType:Play()
    SetJumpingTo(true)
    task.wait(CDType)
    Debounce = false
end
south quartz
cunning ether
#

ah now it worked

cunning ether
#

That was one of my first problems which is also the reason why i only write in my local script

south quartz
#

You could play the animation when done tp the player to the new position, to make smooth flow but you meant have to reanimate it, but that I think I’m over complicated it again there probably more a simple way agin don’t have my pc on me atm

cunning ether
#

I mean the threat is Titlet Dash using HumanoidRootPart:ApplyImpulse() not changing the CFrame

cunning ether
#

I'VE FINNALLY FIXED IT

#

I'll be sending the script and the solution to my problem so if for some reason someone will have the same problem like me one day

#

So once again here is the script:

#
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer.Character
local DashRF = game:GetService("ReplicatedStorage").RemoteFunctions.DashVFX
local DashRE = game:GetService("ReplicatedStorage").RemoteEvents.DashRemoteEvent
local Humanoid = player:WaitForChild("Humanoid")
local HumRootPart = player:WaitForChild("HumanoidRootPart")
local Debounce = false

local FrontDashAni = script:WaitForChild("FrontDashAni")
local FrontDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(FrontDashAni)
local BackDashAni = script:WaitForChild("BackDashAni")
local BackDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(BackDashAni)
local RightSideDashAni = script:WaitForChild("RightSideDashAni")
local RightSideDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(RightSideDashAni)
local LeftSideDashAni = script:WaitForChild("LeftSideDashAni")
local LeftSideDashAniTrack = player:WaitForChild("Humanoid"):LoadAnimation(LeftSideDashAni)


local AirForce = 75
local GroundForce = 75
local AirCD = 1
local GroundCD = 0.75
local SideDashCD = 0.60



local function SetJumpingTo(boolean)
    Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, boolean)
end
#
local function Calculate(LookVector, Boolean, State)
    if LookVector == true then
        local LookV = HumRootPart.CFrame.LookVector
        local Direction = Vector3.new(LookV.X, 0, LookV.Z).Unit
        local Mass = HumRootPart.AssemblyMass
        local Force = 0
        if Boolean == true then
            if State == "Ground" then
                Force = GroundForce
            end
            if State == "Air" then
                Force = AirForce
            end
        end
        if Boolean == false then
            if State == "Ground" then
                Force = -GroundForce
            end
            if State == "Air" then
                Force = -AirForce
            end
        end
        return Direction, Mass, Force
    else
        local Direction = HumRootPart.CFrame.RightVector
        local Mass = HumRootPart.AssemblyMass
        local Force = 0
        if Boolean == true then
            if State == "Ground" then
                Force = GroundForce
            end
            if State == "Air" then
                Force = AirForce
            end
        end
        if Boolean == false then
            if State == "Ground" then
                Force = -GroundForce
            end
            if State == "Air" then
                Force = -AirForce
            end
        end
        return Direction, Mass, Force
    end
end

local function EndOfDashFunction(AnimationType, CDType)
    AnimationType:Play()
    task.wait(0.23)
    SetJumpingTo(true)
    task.wait(CDType - 0.23)
    Debounce = false
end
#
local function Dash(FrontDash, LookVector, Tag, Animation)
    if player:HasTag("Jumping") then
        DashRE:FireServer(Tag, "Air")
        local Direction, Mass, Force = Calculate(LookVector, FrontDash, "Air")
        print("AirDash")
        HumRootPart:ApplyImpulse(Direction * Mass * Force)
        EndOfDashFunction(Animation, AirCD)
    else
        DashRE:FireServer(Tag, "Ground")
        local Direction, Mass, Force = Calculate(LookVector, FrontDash, "Ground")
        print("GroundDash")
        HumRootPart:ApplyImpulse(Direction * Mass * Force)
        Animation:Play()
        task.wait(0.05)
        if player:HasTag("Jumping") then
            EndOfDashFunction(Animation,GroundCD)
        else
            HumRootPart:ApplyImpulse(Direction * Mass * Force)
            print("2nd GroundDash")
            EndOfDashFunction(Animation, GroundCD)
        end
    end
end
rustic plazaBOT
#

studio** You are now Level 6! **studio

cunning ether
#
UIS.InputBegan:Connect(function(Input, IsTyping)
    if Input.KeyCode == Enum.KeyCode.Q and not Debounce then
        SetJumpingTo(false)
        if Debounce == false then
            Debounce = true
            if player:HasTag("ShiftLock") then
                
                if player:HasTag("Pressing W") then
                    Dash(true, true, "FrontDash", FrontDashAniTrack)
                    
                elseif player:HasTag("Pressing S") then
                    Dash(false, true, "BackDash", BackDashAniTrack)
                
                elseif player:HasTag("Pressing A") then
                    Dash(false, false, "LeftSideDash", LeftSideDashAniTrack)
                    
                elseif player:HasTag("Pressing D") then
                    Dash(true, false, "RightSideDash", RightSideDashAniTrack)
                
                else
                    Dash(true, true, "FrontDash", FrontDashAniTrack)
                end
            
            else
                Dash(true, true, "FrontDash", FrontDashAniTrack)
            end
        end
    end
end)
#

So this is the fixed version of a the "Double Impulse" bug. The actual problem is that ApplyImpulse relays a lot on Friction and Matter which made jumping right after a Ground Dash (Which had more Force to make the dash go further even tho there was friction) appear like a double dash of ground and air dash. but the air dash wasn't triggered once. The way i used to fix that issue was weaken the grounddash to the same force of the air dash but in return i would check again after 0.05 seconds if the player is still on the ground while executing a ground dash to then dash them again so they would have their force double of an air dash while beeing completly effected by the friction and when executing the "Bug" the player would only get the Impulse of the AirDash.

#

If there is any chance anyone will be looking at this in the future i don't mind if you dm me to help with ApplyImpulse if you still haven't understood my explaintion as it might be hard to understand because of my bad english

south quartz
#

Could lead future lag issue, but hay if not broke don’t fix it.

#

But if it starts lagging you know what to tackle next’s “optimization”

cunning ether
cunning ether
south quartz
#

Do it in a separate studio file

cunning ether