The character overslide(cannot stop immediately after del LV) after using linear velocity

I am currently trying to make a fighting game. I have made a ability which is jump to the front but I want to know why the character end position is not the middle of the ground smash.

robloxapp-20240830-1843508.wmv (1.1 MB)

It overslides everytime it jump. I tried to anchored the HRP, set the AssemblyLinearVelocity to zero but still cannot work, here are my scripts.

ClientSide :

function ApeModule.FrontJump(plr)
	--Define basic items
	local LocalPlayer = plr
	local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	local Animator = Humanoid:WaitForChild("Animator")
	local HRP = Character:WaitForChild("HumanoidRootPart")

	Character:SetAttribute("SkillInUse", true)
	Humanoid.WalkSpeed = 0
	Humanoid.JumpHeight = 0
	SyncHumanoidRemoteEvent:FireServer({WalkSpeed = 0, JumpHeight = 0}, "ChangeValue", "Humanoid")
	SyncHumanoidRemoteEvent:FireServer({Jumping = false}, "SetStatue", nil)
	
	local FrontJumpReadyAnimLoad = Animator:LoadAnimation(FrontJumpReadyAnim)
	local FrontJumpAnimLoad = Animator:LoadAnimation(FrontJumpAnim) 
	
	repeat task.wait() until FrontJumpReadyAnimLoad.Length > 0 and FrontJumpAnimLoad.Length > 0
	
	FrontJumpReadyAnimLoad:Play()
	
	local FrontJumpReadyAnimLoadConnection = nil
	FrontJumpReadyAnimLoadConnection = FrontJumpReadyAnimLoad.Stopped:Connect(function()
		FrontJumpReadyAnimLoadConnection:Disconnect()
		
		FrontJumpAnimLoad:Play()
		FrontJumpRemoteEvent:FireServer("Start", FrontJumpAnimLoad.Length)
	end)
	
	local FrontJumpAnimLoadConnection = nil
	FrontJumpAnimLoadConnection = FrontJumpAnimLoad.Stopped:Connect(function()
		HRP.Anchored = true
		FrontJumpAnimLoadConnection:Disconnect()
		
		task.spawn(function() CombatModuleScript.cameraShake(0.5, Humanoid) end)
		GroundPunchSound:Play()
		--FireServer
		FrontJumpRemoteEvent:FireServer("End")
		Character:SetAttribute("SkillInUse", false)
		HRP.Anchored = false
	end)
end

ServerSide:

FrontJumpRemoteEvent.OnServerEvent:Connect(function(plr, eventName, moveDuration)	
	local LocalPlayer = plr
	local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
	local Humanoid = Character.Humanoid
	local Animator = Humanoid.Animator
	local HRP = Character.HumanoidRootPart
	
	if(eventName == "Start") then
		task.spawn(function() CombatModuleScript.AddForce(Character, HRP.CFrame.LookVector * 75, moveDuration) end)
	elseif(eventName == "End") then
		HRP.AssemblyLinearVelocity = Vector3.zero
		HRP.Anchored = true
		HRP.AssemblyLinearVelocity = Vector3.zero
		local damageCharacters = CombatModuleScript.CreateHitbox(Vector3.new(7, 5, 7), HRP.CFrame * CFrame.new(0, -1, 0), {Character}, false, nil, nil)
	
		for _, char in pairs(damageCharacters) do
			DamageHandlerModuleScript.TakeDamage(char, DamageValues["FrontJump"])
		end		
		
		
		print(HRP.CFrame)
		task.spawn(function() CombatModuleScript.GroundSmash(HRP.CFrame * CFrame.new(0, -2.5, 0), 3, false) end)
		
		Humanoid.WalkSpeed = 16
		Humanoid.JumpHeight = 7.2
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
		
		HRP.AssemblyLinearVelocity = Vector3.zero
		HRP.Anchored = false
	end
end)

Add force function :

function CombatModule.AddForce(char, forceDirection, second)
	if(second == nil) then second = 0.01 end

	local HRP = char.HumanoidRootPart
	local LinearVelocity = Instance.new("LinearVelocity", HRP)
	local Attachment = Instance.new("Attachment", HRP)
	LinearVelocity.Attachment0 = Attachment
	LinearVelocity.MaxForce = math.huge
	LinearVelocity.VectorVelocity = forceDirection
	
	
	Debris:AddItem(LinearVelocity, second)
	Debris:AddItem(Attachment, second)
end

Thank you

Force is unreliable if you want precise movements. Use BodyPosition instead and continuously update the position of your character. To make an acceleration/deceleration effect you can tween an IntValue and multiply it by the position.

Let me know if you need anything else

2 Likes

but BodyPosition is already Deprecated, I should keep using BodyPosition or I need to use AlignPosition?

It is up to you to decide which constraint to use.

1 Like

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