You can write your topic however you want, but you need to answer these questions:
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.
What is the issue? Include screenshots / videos if possible!
Player gets flung around every time it crashes with collide-able part
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)
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
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?
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
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)
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.
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.