• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


30 Nov, 2024

Updated at 13 Dec, 2024

LinearVelocity Knockback Ragdoll

I’m making a knockback system to my game. The system is fine, except for the way Roblox ragdolls the players. This only happens in cramped spaces and places that are really tight.
I want to minimize the times that the flinging happens and try to still make this smooth.

function module:Knockback(character, start)
	local knockbackTime = 0.2
	local knockbackPower = 100
	
	if not character.PrimaryPart:FindFirstChild("LinearVelocity") then
		local direction = -((start - character.PrimaryPart.Position)).Unit
		
		local attachment = Instance.new("Attachment")
		attachment.Parent = character.PrimaryPart
		
		local linearVelocity = Instance.new("LinearVelocity")
		linearVelocity.Attachment0 = attachment
		linearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
		linearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
		linearVelocity.VectorVelocity = direction
		linearVelocity.ForceLimitsEnabled = false
		linearVelocity.Parent = character.PrimaryPart
		
		local num = Instance.new("NumberValue")
		num.Parent = linearVelocity
		
		local tween = tweenService:Create(num, TweenInfo.new(knockbackTime, Enum.EasingStyle.Circular), {Value = knockbackPower})
		tween:Play()
		
		local connection = runService.Stepped:Connect(function()
			linearVelocity.VectorVelocity = direction * num.Value
		end)
		
		linearVelocity.Destroying:Connect(function()
			connection:Disconnect()
		end)
		
		debris:AddItem(linearVelocity, knockbackTime)
		debris:AddItem(attachment, knockbackTime)
		debris:AddItem(num, knockbackTime)
	end
end

1 post - 1 participant

Read full topic