I am making a combat system and a big issue I have been having when fighting my friends is that often their will be random flinging. This may be due to the linear velocity I use as knockback or the ragdoll script maybe? I am not sure of the causes at all really and would like advice from people experienced in making combat systems. I am also having issues with people flying away when ragdolled and knocked back at an angle.
Here is my code for my ragdoll module, which by the way turns cancollide on for some limb sized parts that I have put in the limbs to ensure they don’t clip through the floor:
local module = {}
-------------------------------------------------------------------------------------------------------
--Ragdolls the given player
function module.Start(character)
--Loops through everything in the character model
for i,v in pairs(character:GetDescendants()) do
--Checks if the item is a motor6D
if v:IsA("Motor6D") then
local socket = Instance.new("BallSocketConstraint",v.Parent)
local Attachment0 = Instance.new("Attachment",v.Part0)
local Attachment1 = Instance.new("Attachment",v.Part1)
socket.Attachment0 = Attachment0
socket.Attachment1 = Attachment1
Attachment0.CFrame = v.C0
Attachment1.CFrame = v.C1
socket.LimitsEnabled= true
socket.TwistLimitsEnabled = true
character.Humanoid.AutoRotate = false
character.Humanoid.WalkSpeed = 0
character.Humanoid.JumpPower = 0
character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
character.Humanoid.RequiresNeck = false
for _,colliders in pairs(character.Colliders:GetChildren()) do
if colliders:IsA("Part") and colliders.Parent.Name ~= "HitBoxes" then
print(colliders.Name)
colliders.CanCollide = true
end
end
v.Enabled = false
end
end
end
-------------------------------------------------------------------------------------------------------
--Makes the player get up from the ragdoll
function module.Stop(character,jumpPower,WalkSpeed)
--Turns the collisions off for the collision parts
for _,colliders in pairs(character.Colliders:GetChildren()) do
if colliders:IsA("Part") and colliders.Parent.Name ~= "HitBoxes" then
print(colliders.Name)
colliders.CanCollide = false
end
end
--Loops through everything in the character model
for i,v in pairs(character:GetDescendants()) do
--Checks if itis a BallSocketConstraint that replaced the previous motor6D
if v:IsA("BallSocketConstraint") then
v.Attachment0:Destroy()
v.Attachment1:Destroy()
v:Destroy()
end
--Checks if the item is a disabled Motor6D
if v:IsA("Motor6D") then
v.Enabled = true
end
end
character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
character.Humanoid.WalkSpeed = WalkSpeed
character.Humanoid.JumpPower = jumpPower
character.Humanoid.AutoRotate = true
character.Humanoid.RequiresNeck = true
end
-------------------------------------------------------------------------------------------------------
return module
Here is the code I use for all of my knockback as well as my dashes:
local Attachment = Instance.new("Attachment",rootPart)
local LinearVelocity = Instance.new("LinearVelocity",Attachment)
LinearVelocity.MaxForce = math.huge
LinearVelocity.VectorVelocity = (game.Workspace:FindFirstChild(PlayerWhoHit.Value).HumanoidRootPart.CFrame.LookVector * KnockbackPower.Value) + Vector3.new(0,UpKnockback.Value,0)
LinearVelocity.Attachment0 = Attachment
game:GetService("Debris"):AddItem(Attachment,0.1)