Player Fling Glitch

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!
    Stop player from flinging whenever they dash.

  2. What is the issue? Include screenshots / videos if possible!
    When a player dashes into the side of a wall, they get flung.

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    Using raycasts to keep player from flinging into a wall or being able to rotate.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

How does the dash work? do you set the root part’s velocity?

1 Like

ye its a linear velocity on the humrootpart

how high is the force you are using? (send a screenshot if you can)

--!strict

wait(3)
print("DashingLoaded")

local DASH_KEY = Enum.KeyCode.Q
local DASH_LENGTH = 0.2
local DASH_POWER = 25
local MAX_DASHES = 2
local GROUND_DASH_COOLDOWN = 0.5
local WALL_BUFFER = 2

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid") :: Humanoid
local rootPart =character:WaitForChild("HumanoidRootPart") :: BasePart

local playerGui = Players.LocalPlayer.PlayerGui
local Cooldown = playerGui:WaitForChild("Stamina")

local isDashingActive = false
local remainingDashes = MAX_DASHES
local canGroundDash = true
local cooldownStateChangedConnection: RBXScriptConnection? = nil

local function waitForLanding()
	while true do
		local state = humanoid:GetState()
		if state ~= Enum.HumanoidStateType.Freefall and state ~= Enum.HumanoidStateType.Jumping then
			break
		end
		task.wait(0.1)
	end

	remainingDashes = MAX_DASHES

	if cooldownStateChangedConnection then
		cooldownStateChangedConnection:Disconnect()
		cooldownStateChangedConnection = nil
	end
end

local function doDash()
	if isDashingActive then return end

	local isGrounded = humanoid:GetState() ~= Enum.HumanoidStateType.Freefall
		and humanoid:GetState() ~= Enum.HumanoidStateType.Jumping

	if isGrounded then
		if not canGroundDash then return end
		canGroundDash = false
		task.delay(GROUND_DASH_COOLDOWN, function()
			canGroundDash = true
		end)
	else
		if remainingDashes <= 0 then return end
		if remainingDashes == 2 then
			Cooldown["1"].ImageColor3 = Color3.new(0,0,0)
		elseif remainingDashes == 1 then
			Cooldown["2"].ImageColor3 = Color3.new(0,0,0)
		end
		remainingDashes -= 1
	end

	isDashingActive = true

	local moveDirection = humanoid.MoveDirection
	moveDirection = Vector3.new(moveDirection.X, 0, moveDirection.Z)

	if moveDirection.Magnitude < 0.1 then
		local cameraLook = workspace.CurrentCamera.CFrame.LookVector
		moveDirection = Vector3.new(cameraLook.X, 0, cameraLook.Z)
	end

	if moveDirection.Magnitude > 0 then
		moveDirection = moveDirection.Unit
	else
		warn("Dash cancelled: moveDirection is zero")
		isDashingActive = false
		return
	end

	if tostring(moveDirection):find("nan") then
		warn("Dash failed: moveDirection contains NaN")
		isDashingActive = false
		return
	end


	local rayOrigin = rootPart.Position
	local raycastParams = RaycastParams.new()
	raycastParams.FilterDescendantsInstances = {character}
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude

	local rayDirection = moveDirection * DASH_POWER
	local rayResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)

	if rayResult then
		local hitDistance = (rayResult.Position - rayOrigin).Magnitude
		if hitDistance <= WALL_BUFFER then
			isDashingActive = false
			warn("Dash canceled: too close to wall")
			return
		else
			rayDirection = moveDirection * (hitDistance - WALL_BUFFER)
		end
	end

	-- Final safety check
	if not rayDirection or rayDirection.Magnitude > 1000 or tostring(rayDirection):find("nan") then
		warn("Dash failed: invalid velocity vector")
		isDashingActive = false
		return
	end


	humanoid.PlatformStand = true

	local bodyVelocity = Instance.new("BodyVelocity")
	bodyVelocity.Velocity = rayDirection / DASH_LENGTH
	bodyVelocity.MaxForce = Vector3.new(1e6, 1e6, 1e6)
	bodyVelocity.P = 1e5
	bodyVelocity.Parent = rootPart

	task.wait(DASH_LENGTH)

	isDashingActive = false
	if bodyVelocity then bodyVelocity:Destroy() end

	-- Keep vertical velocity
	rootPart.AssemblyLinearVelocity = Vector3.new(0, rootPart.AssemblyLinearVelocity.Y, 0)
	humanoid.PlatformStand = false

	-- Landing reset connection
	if not cooldownStateChangedConnection then
		cooldownStateChangedConnection = humanoid.StateChanged:Connect(function(_, newState)
			if newState == Enum.HumanoidStateType.Landed then
				Cooldown["1"].ImageColor3 = Color3.new(1,1,1)
				Cooldown["2"].ImageColor3 = Color3.new(1,1,1)
				task.defer(waitForLanding)
			end
		end)
	end
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == DASH_KEY and not gameProcessedEvent then
		doDash()
	end
end)

awesome. ill edit this reply when i find something.


sorry, i meant bodyvelocity

image
i feel this will create issues - the character will try to correct a lot of the forces that are applied to it.
i suggest directly modifying the velocity of the humanoidrootpart itself:
HumanoidRootPart.AssemblyLinearVelocity = vector3.(insert vector here)

thanks but this didnt work. im still able to be flung :confused:

drat.
i did actually assume that wasn’t gonna fix it.
perhaps this will help, along with what i’ve offered: