How to stop/mitigate LinearVelocity based Dashing physics bugs?

Hi! I’m currently trying to improve my dashing feature in my game. It works well but it still acts very glitchy in the physics department.

If I try to dash towards a wall, I’m bounced back, and if I try to dash into a wedge, I get flinged. Here’s a video showing it:


(Don’t ask why the audio is glitchy, the audio on my Roblox Studio acts weird)

I believe the best approach is to change the HumanoidRootPart’s physics to the best result, but I kind of need help with this…

1 Like

Hello!

You are right! To prevent your character from bouncing, you need to change the physical properties of all collidable parts in your character (or all the parts that your character may bounce off, but this is not a good practice). The properties you need are Elasticity and ElasticityWeight.

Here is an example script showing how to do this (a simple dash implementation is also included):

local UserInputService = game:GetService('UserInputService')

--> Script should be located inside StarterCharacterScripts
local Character = script.Parent
local HumanoidRootPart: BasePart = Character:WaitForChild('HumanoidRootPart')

--> Create the custom physical properties
local physicalProperties = PhysicalProperties.new(
	0.7, -- Default Density (Plastic)
	0.5, -- Default Friction (Plastic)
	0, -- Custom Elasticity
	1, -- Default FrictionWeight (Plastic)
	100 -- Custom ElasticityWeight
)

--> Declare and use the function to set the properties for every collidable BasePart inside the Character
local function SetPhysicalProperties(v: BasePart?)
	if v:IsA('BasePart') and v.CanCollide then
		v.CustomPhysicalProperties = physicalProperties
	end
end

Character.DescendantAdded:Connect(SetPhysicalProperties)
for i,v in pairs(Character:GetDescendants()) do
	SetPhysicalProperties(v)
end

--> Dash
local LastDash = 0
UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and not UserInputService:GetFocusedTextBox() then
		-- Time check
		local CurrentDash = tick()
		if CurrentDash - LastDash < 5 then
			return
		end
		LastDash = CurrentDash
		
		-- Multiplication of the horizontal linear velocity
		HumanoidRootPart.AssemblyLinearVelocity = Vector3.new(HumanoidRootPart.AssemblyLinearVelocity.X * 10, HumanoidRootPart.AssemblyLinearVelocity.Y, HumanoidRootPart.AssemblyLinearVelocity.Z * 10)
	end
end)
3 Likes

That fixed the bounce off issue, I’m going to implement it to my script! However, the wedge problem persists, but I’m pretty sure I know how to fix that, preventing the humanoid from tripping should fix it.
(Oh yeah forgot to mention too that I have a StarterCharacter so I’m guessing changing the physical properties is not needed to be executed via script and it can be just executed manually)

If I don’t have any more problems with this later, I’m marking your post as the solution.

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