How to make LinearVelocity NOT freeze the character?

I’m making a dash script using LinearVelocity ON PURPOSE because I WILL NOT use BodyVelocity or other deprecated classes, but I can’t even get this class to work on the character just to test.

When I try to apply a LinearVelocity to any attachment on the character, regardless of the velocity or maxforce I input, all movement stops and my characters velocity is “paused” until the LinearVelocity constraint is destroyed.

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ContextActionService = game:GetService('ContextActionService')

local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')
local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')
local Animations = ReplicatedStorage['Client Animations']

local Anims = {
    Humanoid:LoadAnimation(Animations["Dash Left"]),
    Humanoid:LoadAnimation(Animations["Dash Backward"]),
    Humanoid:LoadAnimation(Animations["Dash Right"]),
    Humanoid:LoadAnimation(Animations["Dash Forward"]),
}

local DashRayParams = RaycastParams.new()
DashRayParams.FilterType = Enum.RaycastFilterType.Include
DashRayParams.FilterDescendantsInstances = {workspace.Terrain}

local LinearVelocityTemplate = Instance.new('LinearVelocity')
LinearVelocityTemplate.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
LinearVelocityTemplate.PrimaryTangentAxis = Vector3.new(1, 0, 0)
LinearVelocityTemplate.SecondaryTangentAxis = Vector3.new(0, 0, 1)
LinearVelocityTemplate.MaxForce = 900
LinearVelocityTemplate.Parent = script

local DashDuration = 1
local DashCooldown = 1.5
local DashMagnitude = 300
local LastDash = 0

local function FindAngleAnim()
    local Animation, Closest = nil
    local AngleZ = HumanoidRootPart.CFrame.LookVector:Dot(Humanoid.MoveDirection)
    local AngleX = HumanoidRootPart.CFrame.RightVector:Dot(Humanoid.MoveDirection)
    local DashAngle = math.atan2(AngleZ, AngleX)

    for Index, Anim in pairs(Anims) do
	    local IndexAngle = (Index - 3) * (math.pi / 2)
	    local DiffAngle = math.abs((Index == 1 and -math.abs(DashAngle) or DashAngle) - IndexAngle)
	    if not Animation or DiffAngle < Closest then
		    Animation = Anim
		    Closest = DiffAngle
	    end
    end

    return Animation
end

local function ApplyDashForce(Duration: number, ForceAnim: AnimationTrack)
    local Force = LinearVelocityTemplate:Clone()
    local DashDirection = Humanoid.MoveDirection.Magnitude >= 0.01 and Humanoid.MoveDirection or -HumanoidRootPart.CFrame.LookVector
    Force.PlaneVelocity = Vector2.new(DashDirection.X * DashMagnitude, DashDirection.Z * DashMagnitude)
    Force.Attachment0 = _G.Chakra.Plexus -- Attachment at center of Torso, verified alr
    Force.Parent = HumanoidRootPart

    local AnimationTrack = ForceAnim or FindAngleAnim()
    AnimationTrack:GetMarkerReachedSignal('Pause'):Connect(function()
	    AnimationTrack:AdjustSpeed(0)
    end)

    AnimationTrack:Play()
    task.delay(Duration, function()
	    Force:Destroy()
	    AnimationTrack:AdjustSpeed(1)
    end)
end

ContextActionService:BindAction('Dash', function(Action, State, Input)
    if not Humanoid then return end
    if Action ~= 'Dash' then return end
    if State ~= Enum.UserInputState.Begin then return end
    if os.clock() - LastDash < DashCooldown + DashDuration then return end
    LastDash = os.clock()

    ApplyDashForce(DashDuration, Humanoid.MoveDirection.Magnitude < 0.01 and Anims[2] or nil)
end, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonB)

I tried copying and pasting the LinearVelocity the ApplyDashForce function creates into a dummy rig and THAT worked??? Someone please help me…

2 Likes

I made this like minimalist version of that using your code, and it seems to work (it doesn’t necessarily go in the right direction half the time but the player does go flying??)

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local ContextActionService = game:GetService('ContextActionService')

local Character = script.Parent
local Humanoid = Character:WaitForChild('Humanoid')
local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart')

local attach = Instance.new("Attachment",HumanoidRootPart)

local DashRayParams = RaycastParams.new()
DashRayParams.FilterType = Enum.RaycastFilterType.Include
DashRayParams.FilterDescendantsInstances = {workspace.Terrain}

local LinearVelocityTemplate = Instance.new('LinearVelocity')
LinearVelocityTemplate.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
LinearVelocityTemplate.PrimaryTangentAxis = Vector3.new(1, 0, 0)
LinearVelocityTemplate.SecondaryTangentAxis = Vector3.new(0, 0, 1)
LinearVelocityTemplate.MaxForce = 90000
LinearVelocityTemplate.Parent = script

local DashDuration = 1
local DashCooldown = 1.5
local DashMagnitude = 80
local LastDash = 0

local function ApplyDashForce(Duration: number, ForceAnim: AnimationTrack)
	local Force = LinearVelocityTemplate:Clone()
	local DashDirection = Humanoid.MoveDirection.Magnitude >= 0.01 and Humanoid.MoveDirection or -HumanoidRootPart.CFrame.LookVector
	Force.PlaneVelocity = Vector2.new(DashDirection.X * DashMagnitude, DashDirection.Z * DashMagnitude)
	Force.Attachment0 = attach -- Attachment at center of Torso, verified alr
	Force.Parent = HumanoidRootPart
	
	task.delay(Duration, function()
		Force:Destroy()
	end)
end

ContextActionService:BindAction('Dash', function(Action, State, Input)
	if not Humanoid then return end
	if Action ~= 'Dash' then return end
	if State ~= Enum.UserInputState.Begin then return end
	if os.clock() - LastDash < DashCooldown + DashDuration then return end
	LastDash = os.clock()
	ApplyDashForce(DashDuration)
end, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonB)

Is there a problem w your Chakra attachment ?

1 Like

Sounds like it might be an Assembly de-sync. While your character is “paused”, check the “AssemblyRootPart” property under any of the body parts on the client and server. If they are different, it means Roblox has stopped recognizing them as the same Assembly and your client has stopped trying to simulate it.

2 Likes

The chakra attachment is actually inside of torso, not hrp. Do you think thats causing the assembly desync that @Judgy_Oreo explained? If so, the fix could be just using an hrp attachment instead.

Thank you both of you, that worked! Im thinking my bizare animations (moving the torso so far from the hrp, where the LinearVelocity was) caused the desync which is why removing them gave strange results. But changing my Attachment0 to the HRP.RootAttachment worked!

1 Like

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