Player Gains more momentum Midair while dashing

The issue is the title. (I want the player to dash the SAME distance in the air compared to the ground) I have tried to use custom physical properties to adjust friction but it doesn’t work. (not sure if my way of implementation is wrong) I tried detecting if the character is jumping however it is really janky.


Help would be appreciated.

local VelocityDuration = 0.05
local RegainFrictionDelay = 0.3 --  After Velocity is gone
local VelocityForce = 100
local HotKeys = {
	["Q"] = Vector3.new(-1, 0, 0);
	["E"] = Vector3.new(1, 0, 0);
}

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Dasher = {}

function Dasher:Start()
	UserInputService.InputBegan:Connect(function(Input, GPE)
		if GPE then return end
		
		local Direction = HotKeys[Input.KeyCode.Name]
		if Direction then
			local function FrictionAdjustment(Friction)
				for _, BodyPart in pairs(Player.Character:GetChildren()) do
					if BodyPart:IsA("BasePart") then
						local CurrentPhy = BodyPart.CurrentPhysicalProperties
						local PhyProperties = PhysicalProperties.new(CurrentPhy.Density, Friction, CurrentPhy.Elasticity, CurrentPhy.FrictionWeight, CurrentPhy.ElasticityWeight)
						BodyPart.CustomPhysicalProperties = PhyProperties
					end
				end
			end
			
			--Please spare me for using deprecated bodymovers
			local Camera = workspace.CurrentCamera.CFrame
			local X, Y, Z = Camera:ToOrientation()
			Camera = CFrame.new(Camera.Position.X, Camera.Position.Y, Camera.Position.Z)*CFrame.Angles(math.rad(0), Y, Z)
			
			local RootPart = Player.Character:WaitForChild("HumanoidRootPart")
			local Humanoid : Humanoid = Player.Character:WaitForChild("Humanoid")
			
			local Velocity = Camera:VectorToWorldSpace(Direction) * VelocityForce
			Velocity = Vector3.new(Velocity.X, 0, Velocity.Z)
			
			local NewVelocity = Instance.new("BodyVelocity")
			NewVelocity.MaxForce = Vector3.new(math.huge, 0, math.huge)
			NewVelocity.Velocity = Velocity
			NewVelocity.Parent = RootPart
			
			FrictionAdjustment(0); RootPart.CanCollide = true -- Prevents phasing through solid objects
			
			task.wait(VelocityDuration)
			NewVelocity:Destroy(); RootPart.CanCollide = false
			
			task.wait(RegainFrictionDelay)
			FrictionAdjustment(0.3)
		end
	end)
end

return Dasher

I don’t really think you can change this. These are Roblox physics you’re dealing with here. The player will automatically gain more momentum midair while they are dashing because that was set by Roblox. If you want to change it, you’ll have to dive deep into Roblox’s system/scripts that you normally can’t access and try changing that up. Other than that, I don’t think much can override this.

I’ve seen games that isn’t affected by this issue but alright. I’m somewhat sure that I just screwed up on the friction or the way that the force is applied.

2 Likes

Same result… (am I doing something wrong?)

local VelocityDuration = 0.1
local RegainFrictionDelay = 0.3 --  After Velocity is gone
local VelocityForce = 100
local HotKeys = {
	["Q"] = Vector3.new(-1, 0, 0);
	["E"] = Vector3.new(1, 0, 0);
}

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Dasher = {}

function Dasher:Start()
	UserInputService.InputBegan:Connect(function(Input, GPE)
		if GPE then return end
		
		local Direction = HotKeys[Input.KeyCode.Name]
		if Direction then
			local function FrictionAdjustment(Friction)
				for _, BodyPart in pairs(Player.Character:GetChildren()) do
					if BodyPart:IsA("BasePart") then
						local CurrentPhy = BodyPart.CurrentPhysicalProperties
						local PhyProperties = PhysicalProperties.new(CurrentPhy.Density, Friction, CurrentPhy.Elasticity, CurrentPhy.FrictionWeight, CurrentPhy.ElasticityWeight)
						BodyPart.CustomPhysicalProperties = PhyProperties
					end
				end
			end
			
			--Please spare me for using deprecated bodymovers
			local Camera = workspace.CurrentCamera.CFrame
			local X, Y, Z = Camera:ToOrientation()
			Camera = CFrame.new(Camera.Position.X, Camera.Position.Y, Camera.Position.Z)*CFrame.Angles(math.rad(0), Y, Z)
			
			local RootPart = Player.Character:WaitForChild("HumanoidRootPart")
			local Humanoid : Humanoid = Player.Character:WaitForChild("Humanoid")
			
			local Velocity = Camera:VectorToWorldSpace(Direction) * VelocityForce
			Velocity = Vector3.new(Velocity.X, 0, Velocity.Z)
			
			local NewAttachment = Instance.new("Attachment", RootPart)
			local NewVelocity = Instance.new("LinearVelocity")
			NewVelocity.MaxForce = math.huge
			NewVelocity.VectorVelocity = Velocity
			NewVelocity.Attachment0 = NewAttachment
			NewVelocity.Parent = RootPart
			
			FrictionAdjustment(0); RootPart.CanCollide = true -- Prevents phasing through solid objects
			
			task.wait(VelocityDuration)
			NewVelocity:Destroy(); NewAttachment:Destroy(); RootPart.CanCollide = false
			
			task.wait(RegainFrictionDelay)
			FrictionAdjustment(0.3)
		end
	end)
end

return Dasher
1 Like

Roblox’ engine factors in friction, this can be change on each part individually by enabling CustomPhysicalProperties in the respective property tabs. In there you can change the friction. You can try removing friction entirely for the player while they’re dashing and re-enable it as needed. I’m not positive this will work, but just a suggestion.

Either set the velocity of the player to 0 after the dash ends or you could also use AlignPosition.

I tried that solution, I’m not sure if I implemented it correctly (code is in the post)

Could you reduce the velocity based on the extra velocity being applied to the player when they are jumping?

Thank you (I set the velocity after the dash ends). Here is the code if it helps anybody:

local VelocityDuration = 0.05
local VelocityForce = 150
local HotKeys = {
	["Q"] = Vector3.new(-1, 0, 0);
	["E"] = Vector3.new(1, 0, 0);
}

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Dasher = {}

function Dasher:Start()
	UserInputService.InputBegan:Connect(function(Input, GPE)
		if GPE then return end

		local Direction = HotKeys[Input.KeyCode.Name]
		if Direction then
			--Please spare me for using deprecated bodymovers
			local Camera = workspace.CurrentCamera.CFrame
			local X, Y, Z = Camera:ToOrientation()
			Camera = CFrame.new(Camera.Position.X, Camera.Position.Y, Camera.Position.Z)*CFrame.Angles(math.rad(0), Y, Z)

			local RootPart = Player.Character:WaitForChild("HumanoidRootPart")
			local Humanoid : Humanoid = Player.Character:WaitForChild("Humanoid")

			local Velocity = Camera:VectorToWorldSpace(Direction) * VelocityForce
			Velocity = Vector3.new(Velocity.X, 0, Velocity.Z)

			local NewVelocity = Instance.new("BodyVelocity")
			NewVelocity.MaxForce = Vector3.new(math.huge, 0, math.huge)
			NewVelocity.Velocity = Velocity
			NewVelocity.Parent = RootPart
			
			RootPart.CanCollide = true -- Prevents phasing through solid objects
			
			task.wait(VelocityDuration/1.5)
			
			local VelocityRemove = Velocity/8
			for i = 1, 8 do
				NewVelocity.Velocity -= VelocityRemove
				task.wait((VelocityDuration-VelocityDuration/1.5)/8)
			end
			
			NewVelocity.Velocity = Vector3.one*0; task.wait()
			NewVelocity:Destroy(); RootPart.CanCollide = false
		end
	end)
end

return Dasher
1 Like

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