Smooth knock back implementation problem

Hi

I am creating a knock back function for my combat module and want all clients to experience a smooth knock back.

The main issue I’m having is that the knock back only looks good for one client at a time and is situational. If the knock back is applied to another player it looks smooth on their client, if the knock back is applied to a dummy it only looks smooth on the attackers client.

I have tried using :SetNetworkOwner() as seen in this thread: How to achieve smooth knockback across all clients?

Example without :SetNetworkClient():
https://gyazo.com/cbf95fae567421e04998628284d83a88

Example with :SetNetworkClient()
https://gyazo.com/b2770472b650516399a55df3d3469129

I just want to clarify that the knock back is typically using a lot less force however in these examples I am using a greater force to highlight the issue.

This code is stored in a module script combat handler as a separate function which is called when the player lands a successful blow.

local function knockback(plrChar,eChar,speed,sequence)
	if plrChar and eChar then
		local phrp = plrChar:FindFirstChild("HumanoidRootPart")
		local ehrp = eChar:FindFirstChild("HumanoidRootPart")

		local attach = Instance.new('Attachment',ehrp)

		local lv = Instance.new("LinearVelocity",ehrp)
		lv.Name = "Knockback"
		lv.Attachment0 = attach
		lv.MaxForce = math.huge

		if string.len(sequence) <4 then 
			if players:GetPlayerFromCharacter(ehrp.Parent) then
				ehrp:SetNetworkOwner(players:GetPlayerFromCharacter(ehrp.Parent))
			else
				ehrp:SetNetworkOwner(players:GetPlayerFromCharacter(phrp.Parent))
			end
			lv.VectorVelocity =  phrp.CFrame.LookVector*speed+Vector3.new(0,0,1)
		else
			if players:GetPlayerFromCharacter(ehrp.Parent) then
				ehrp:SetNetworkOwner(players:GetPlayerFromCharacter(ehrp.Parent))
			else
				ehrp:SetNetworkOwner(players:GetPlayerFromCharacter(phrp.Parent))
			end
			lv.VectorVelocity =  phrp.CFrame.LookVector*speed+Vector3.new(0,0,1)			lv.VectorVelocity =  phrp.CFrame.LookVector*speed+Vector3.new(0,0,1)
		end
		game.Debris:AddItem(lv,.15)
		lv.Destroying:Connect(function()
			ehrp:SetNetworkOwnershipAuto()
		end)
	end
end

Any help or suggestions would be greatly appreciated and thank you for reading this post.

This is my first ever post in the developer forums so apologies if there is anything wrong with formatting or my post in general.

~ pres

1 Like

You just showed same exact gifs on those examples
image
I can’t know the difference

Continuing the discussion from Smooth knock back implementation problem:

Hi

Thanks for the response, I edited the post to include the correct gifs, I apologise for that.

I also tried to tween the knock back as seen in this YouTube video: How to Make a Knockback Attack Script | Roblox Studio Tutorial - YouTube however it achieves similar results.

local function newknockback(plrChar,eChar,speed,sequence)
	if plrChar and eChar then
		local phrp = plrChar:FindFirstChild("HumanoidRootPart")
		local ehrp = eChar:FindFirstChild("HumanoidRootPart")
		
		
		local attach = Instance.new("Attachment",ehrp)
		local lv = Instance.new("LinearVelocity",attach)
		
		lv.Name = "Knockback"
		lv.Attachment0 = attach
		lv.MaxForce = math.huge
		
		local lookVector = phrp.CFrame.LookVector
		lv.VectorVelocity = lookVector * speed

		local tween = ts:Create(lv, kbtween, {VectorVelocity = lookVector * 0.1})
		tween:Play()
		game.Debris:AddItem(attach, 0.3)
	end
end

Was my code, and this was the result: https://gyazo.com/9c58cffd4fdc958bc7bfbb4a96bcf070

What i do in this situation:

Creating a LocalScript inside a player that triggers from some RemoteEvent

local lv = game.ReplicatedStorage:WaitForChild("LocalVelocityEvent")

lv.OnClientEvent:Connect(function(...) --Ur velocity parameters (force, velocity, etc.)
	--creating velocity in player's humanoidrootpart
end)

So on the other side, Server side, i fire event to player who’s getting attacked.

local lv = game.ReplicatedStorage:WaitForChild("LocalVelocityEvent")

local function newknockback(plrChar,eChar,speed,sequence)
	if plrChar and eChar then
		local phrp = plrChar:FindFirstChild("HumanoidRootPart")
		local ehrp = eChar:FindFirstChild("HumanoidRootPart")
		
		if players:GetPlayerFromCharacter(ehrp.Parent) then
			lv:FireClient(players:GetPlayerFromCharacter(ehrp.Parent), parameters, parameters, etc..) --You get me
		else
			local attach = Instance.new("Attachment",ehrp)
			local lv = Instance.new("LinearVelocity",attach)
			
			lv.Name = "Knockback"
			lv.Attachment0 = attach
			lv.MaxForce = math.huge
			
			local lookVector = phrp.CFrame.LookVector
			lv.VectorVelocity = lookVector * speed
	
			local tween = ts:Create(lv, kbtween, {VectorVelocity = lookVector * 0.1})
			tween:Play()
			game.Debris:AddItem(attach, 0.3)
		end
	end
end

LocalVelocity makes knockbacking other players very smooth, since its not Server pushing them but their Client, ofc safety reasons - They can disable that script with an exploit, but hey! Its still a solution right?

1 Like

Hi

It works smoothly when it comes to PVP however when I am hitting the dummies the same problem persists.

Thanks for your help

2 Likes

I think you can set the networkowener to the attacker to make it smoother but it will cause security problems

have you solved this problem yet? i’m having same issue

Hi . I do have some solutions. when you hit a ‘victim’ and the victim is a player’s character, you will want to fire a remote event from server to that player’s client . in the remote event perimeter, you will want to send the force od the knockback to the client . if the victim is not a player 's character, you have to handle the knockback on the server . it will be choppy unless you give the attacker’s player network ownership. keep in mind by doing so , you allow the attacker to just void the victim

1 Like