you’re giving the player near infinite force for 0.07 seconds, causing the player to fling upon hitting a wall
you should lower it down to around 500-1000.
Adding onto what @MikeartsRBLX said, if decreasing the values doesn’t entirely give you a solution; you can try setting a raycast from the player’s head, when this ray hits an instance you stop the dash effect.
local RAY_DISTANCE = 15
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = Character:GetDescendants() -- Just in case, ignore if the character triggers the ray
Params.FilterType = Enum.RaycastFilterType.Exclude
local headPosition = Character.Head.Position
local headDirection = Character.Head.CFrame.LookVector * RAY_DISTANCE
local headResult = workspace:Raycast(headPosition, headDirection, Params)
if headResult and headResult.Instance then
-- Remove BodyVelocity
end
this works, but you would need an efficient loop for it if you want to check every wall the player hits while not potentially causing performance issues.
local function ApplyVelocityWithCollisionCheck(Character, Direction, Force, MaxDuration)
-- Used ChatGPT for this because i suck with raycast
local Humanoid = Character:FindFirstChild("Humanoid")
local HRP = Character:FindFirstChild("HumanoidRootPart")
if not Humanoid or not HRP then return end
-- Prevent falling state
Humanoid.PlatformStand = true
local BV = Instance.new("BodyVelocity")
BV.MaxForce = Vector3.new(100000, 0, 100000) -- Constrain to horizontal movement
BV.Velocity = Direction * Force
BV.Parent = HRP
local RaycastParams = RaycastParams.new()
RaycastParams.FilterDescendantsInstances = {Character} -- Ignore the character itself
RaycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local StartTime = tick()
local EndTime = StartTime + MaxDuration
local RayLength = Force * MaxDuration -- Calculate the max range based on speed and duration
while tick() < EndTime do
local RayOrigin = HRP.Position
local RayDirection = Direction * RayLength -- Extend the ray length dynamically
local RayResult = workspace:Raycast(RayOrigin, RayDirection, RaycastParams)
if RayResult then
-- Collision detected, stop the movement and adjust position to avoid clipping
BV:Destroy()
-- Optional: Move the character slightly back to prevent clipping into the wall
HRP.CFrame = CFrame.new(RayResult.Position - Direction * 1)
-- Reset falling prevention
Humanoid.PlatformStand = false
return
end
task.wait(0.01) -- Check for collisions every frame
end
-- Reset falling prevention
Humanoid.PlatformStand = false
-- Destroy BodyVelocity after the duration
BV:Destroy()
end
-- Here is how it gets fired
local Direction = HRP.CFrame.LookVector -- Movement direction
local Force = 150 -- Movement speed
local Duration = 0.07 -- Max duration of movement
ApplyVelocityWithCollisionCheck(Character, Direction, Force, Duration)