I’m making a knockback for a punch, and I’m having different results depending on what the FloorMaterial. e.g Air and plastic
I’ve removed all friction from game.Workspace with a for loop that gets Descendants, and also lowered the speed characters travel through air or when falling down.
Removes friction from game.Workspace
for i,v in pairs(game:GetService("Workspace"):GetDescendants()) do
if (v.ClassName == "Part" or v.ClassName == "MeshPart" or v.ClassName == "CornerWedgePart" or v.ClassName == "WedgePart" or v.ClassName == "SpawnLocation") then
local density = 1;
local friction = 0;
local elasticity = 0;
local frictionWeight = 0;
local elasticityWeight = 0;
v.CustomPhysicalProperties = PhysicalProperties.new(density, friction, elasticity, frictionWeight, elasticityWeight);
end;
end;
Knockback
local heartbeat = nil;
local timePassed = 0;
local hum = hit.Parent:FindFirstChild("Humanoid");
heartbeat = runService.Heartbeat:Connect(function(dt)
-- If player is freefalling it halves the the speed of AssemblyLinearVelocity
if (hum:GetState() == Enum.HumanoidStateType.Freefall or hum:GetState() == Enum.HumanoidStateType.Ragdoll or hum:GetState() == Enum.HumanoidStateType.Flying or hum.FloorMaterial == "Air") then
hrp.AssemblyLinearVelocity = Vector3.new(lookVector.X * velocityNum / 2, 0, lookVector.Z * velocityNum / 2);
else
hrp.AssemblyLinearVelocity = Vector3.new(lookVector.X * velocityNum, 0, lookVector.Z * velocityNum);
end;
timePassed += dt;
-- Time Limit is set to 5 seconds outside the scope
if (timePassed >= timeLimit) then
heartbeat:Disconnect();
-- Slows down player at 10% of speed per 1/10 second
while (hrp.AssemblyLinearVelocity.X > 0 and hrp.AssemblyLinearVelocity.Y > 0 and hrp.AssemblyLinearVelocity.Z > 0) do
hrp.AssemblyLinearVelocity = Vector3.new(hrp.AssemblyLinearVelocity.X - hrp.AssemblyLinearVelocity.X * 0.1, hrp.AssemblyLinearVelocity.Y - hrp.AssemblyLinearVelocity.Y * 0.1, hrp.AssemblyLinearVelocity.Z - hrp.AssemblyLinearVelocity.Z * 0.1);
task.wait(0.01);
end;
if (hit.Parent:FindFirstChild("Humanoid")) then
hit.Parent["Humanoid"].AutoRotate = true;
end;
return;
end;
end);
Result:
On Surface
In Air
Character travels further in air, compared to surface even after removing friction from game.Workspace.