How can i create a dash system without the character flinging?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the dash to not fling the player, every time it crashed into a collide-able part it flings the player.

  2. What is the issue? Include screenshots / videos if possible!

Player gets flung around every time it crashes with collide-able part

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I have look all around devforum, i try the solutions i find on other posts but none of them have worked for me so far.


local Dash_Normal = 20 
local Dash_Timeout = 0.15
local Can_Dash = true 

function DashForward(root)
	local i = Instance.new('BodyPosition')
	i.MaxForce = Vector3.new(1000000,0,1000000)
	i.P = 100000
	i.D = 2000
	i.Position = (root.CFrame*CFrame.new(0,0,-Dash_Normal)).Position 
	i.Parent = root
	coroutine.wrap(function()
		wait(.2)
		i:Destroy()
	end)()
end

UIS.InputBegan:Connect(function(input,istyping)
	if istyping then return end
	if input.KeyCode == Enum.KeyCode.Q then
		if Can_Dash == true then
			Can_Dash = false
			DashForward(Root)
			coroutine.wrap(function()
				wait(Dash_Timeout)
				Can_Dash = true
			end)()
		end
	end
end)
2 Likes

You just have to change i.MaxForce to the smaller value. For example:

i.MaxForce = Vector3.new(100000,0,100000)
1 Like

You can also try using root:ApplyImpulse() using the root.CFrame.LookVector() and a constant multiplier like 1500, instead of inserting and destroying a BodyPosition object

1 Like

it somewhat worked but for some reason now it just makes me stuck inside of the part instead of flinging me, any idea on how I could fix that?

1 Like

First of all: have you tried reducing the maxforce values to 20,000? You can try to reduce the amount of i.P and i.D
Secondly: I don’t really understand what “stuck in an object” means. Does the cancollide of the object equal true?

1 Like

so like the player gets stuck in the object even though the cancollide is true, and no i have not lowered the i.P and i.D values yet ill remove a 0 from them

1 Like

No matter how hard I try, I can’t get stuck in the object. Maybe the problem is in your part itself?

2 Likes

Anyways, i created more advanced dash system. You can change wall offset to determine how far it will be from the wall:

local Dash_Normal = 20
local wallOffset = 2
local Dash_Timeout = 0.15
local Can_Dash = true 

function DashForward(root)
	local i = Instance.new('BodyPosition')
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.FilterDescendantsInstances = {char}
	raycastParams.IgnoreWater = true
	local result = workspace:Raycast(root.Position, Root.CFrame.LookVector * Dash_Normal, raycastParams)
	
	local dashDistance = Dash_Normal
	if result then
		dashDistance = result.Distance - wallOffset
	end
	
	i.MaxForce = Vector3.new(40000,0,40000)
	i.P = 100000
	i.D = 1000
	i.Position = (root.CFrame * CFrame.new(0, 0, -dashDistance)).Position 
	i.Parent = root
	
	coroutine.wrap(function()
		wait(.2)
		i:Destroy()
	end)()
end

UIS.InputBegan:Connect(function(input, istyping)
	if istyping then return end
	if input.KeyCode == Enum.KeyCode.Q then
		if Can_Dash then
			Can_Dash = false
			DashForward(Root)
			coroutine.wrap(function()
				wait(Dash_Timeout)
				Can_Dash = true
			end)()
		end
	end
end)
2 Likes

for some reason it like bounces back a little even if im not near any objects

1 Like

Happens due to the maxforce. If its too big it will cause the player to get stuck in a part, or get flinged. Also it would be better to use a LineForce or a LinearVelocity due to those not being deprecated (unless bodyposition isnt deprecated). You could also apply velocity to the player’s AssemblyLinearVelocity since that automatically handles maxforce and friction for you.

2 Likes

how would i go on and do that?

1 Like

Preferably I would use AssemblyLinearVelocity since its already initialized.

local function ApplyVelocity(Root: Part, Velocity: Vector3)
    Root.AssemblyLinearVelocity = Velocity
end

ApplyVelocity(Character.PrimaryPart, Vector3.new(10,0,0)) -- If r15 it will be HumanoidRootPart r6 is Head

You will have to play around with how much velocity you add to get the result you want.

1 Like

would i do this instead of the bodyposition?

1 Like

i tried this but the character moves very small amounts, and if i change it to a bigger number they just get flung very far away

1 Like

I seem to have figured it out, i changed the P value to 200000 and changed the D value to 2000 and now it works perfect, thank you!

1 Like

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