Help with dashing system

Hi guys,
So currently i have just stepped into coding,
Im trying to code a Dash system using @overflowed method which is using BodyPosition.
But here is my problem, although i was able to make the character to not fling but my character still get a push back force that allow player to exploit and create a further and more powerful dash.
So, i wonder if there is any other solution to replace BodyPosition or just simply fix the exploit!

Thank you all!

The codes
local Player = game:GetService("Players")
local character = script.Parent
local HRP = character:WaitForChild("HumanoidRootPart")

local uis = game:GetService("UserInputService")

local DashPower = 20

local animation = character:WaitForChild("Humanoid")

local XDash = 0
local ZDash = 0 
function Dash(root,anima)
animation:SetStateEnabled(Enum.HumanoidStateType.FallingDown,false)
    
    local BP = Instance.new('BodyPosition')
    BP.MaxForce = Vector3.new(1000000,0,1000000)
    BP.P = 100000
    BP.D = 2000
    BP.Position = (root.CFrame*CFrame.new(XDash, 0, ZDash)).Position
    BP.Parent = root

    wait(0.15)
    print("YES")
    BP:Destroy()
    
end

local debounce = false

local CD = 0.75

uis.InputBegan:Connect(function(key, gpe)
    if gpe then return end
    if key.KeyCode == Enum.KeyCode.Q and debounce == false then
        
        local Front = uis:IsKeyDown(Enum.KeyCode.W) or character:WaitForChild("Humanoid").MoveDirection.Magnitude == 0
        local Back = uis:IsKeyDown(Enum.KeyCode.S) 
        local Left = uis:IsKeyDown(Enum.KeyCode.A) 
        local Right = uis:IsKeyDown(Enum.KeyCode.D)
        
        local anim
        
        if uis:IsKeyDown(Enum.KeyCode.W) or character:WaitForChild("Humanoid").MoveDirection.Magnitude == 0 then
            ZDash = -DashPower
            XDash = 0
            anim = animation:LoadAnimation(script.FDash)
        
        elseif uis:IsKeyDown(Enum.KeyCode.S)  then
            ZDash = DashPower
            XDash = 0
            anim = animation:LoadAnimation(script.BDash)
        
        elseif uis:IsKeyDown(Enum.KeyCode.A)  then
            XDash = -DashPower
            ZDash = 0

            anim = animation:LoadAnimation(script.LDash)
        
        elseif uis:IsKeyDown(Enum.KeyCode.D) then
            XDash = DashPower
            ZDash = 0
            anim = animation:LoadAnimation(script.RDash)
        end
        
        debounce = true
        Dash(HRP,anim)
        wait(CD)
        debounce = false
    end
end)
1 Like

Well from what i can remember BodyPosition is deprecated and you can use Align orientation instead. I shall continue to look further into your issue.

AlignOrientation | Roblox Creator Documentation

Edit: Also uis:IsKeyDown() is also deprecated you should use uis.Inputbegan and uis.InputEnded instead.

Edit 2: Why are you defining variables that you are not using? It normally helps when using variables so you may want to use them instead of only defining them.

Edit 3: If updating from the deprecated services and objects does not fix it then it is just roblox’s physics and you can simply fix it by using either surrounding the players Left, Right, Forward, and Backward position with a raycast or roblox’s newest addition ShapeCasts and checking if the current state is being lunged in the direction and then removing the velocity once you start moving away from said lunging direction. I recommend the ShapeCasts as it is supposedly more accurate. There are 2 types, BlockCasts, and SphereCasts, you can choose either one you want.

Raycasting | Roblox Creator Documentation
SphereCast | Roblox Creator Documentation
BlockCast | Roblox Creator Documentation

3 Likes

I used LinearVelocity for my Dash System, try using that

No that would not work. What this person is looking for is why they are bouncing back. A linear velocity is only meant to go in one direction. When doing things like this you can either use ApplyImpulse() or you can use as i stated above AlignOrientation. Linear velocities also can make it quite slow and hard to work with when making a dash system.

lower the .P value of your bodyposition

like how would u set this up tho

well the raycast will equate to a vector3 value so you just need to check if the value is going down. So you can just check if the integer changed and if it did then is it less the its current value. Here is an example script only doing the back of the player

local rayOrigin = Game.Workspace.LocalPlayer.Character.HumanoidRootPart.Position
local rayDirection = Vector3.new(0, -100, 0)

local IsDashing = false --make sure to have it turn to true when you are dashing

local Raycast = WorldRoot:Raycast(rayOrigin, rayDirection)
--note Raycast.Position is where the line is being intersected at and not where it starts.
-- when using ~= then you are checking if the object does not equal the other object. Example 
-- if 1~= 2 then print('one does not equal 2') end
-- then it would print 1 does not equal 2
local function check()
        If Raycast.Position.x ~= Raycast.Position.x - 1 and IsDashing == true or Raycast.Position.y ~= Raycast.Position.y - 1 and IsDashing == true then
        print('no bounce back is happening')
        else
        game.Players.LocalPlayer.Character.HumanidRootPart.AlignOrientation:destroy()
end

Raycast.Position.Changed:Connect(check())

let me know if it does not work as i am not in studio to test it. Also this is assuming you already have a dash system setup.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.