hi guys, i made a cool R6 FootPlanting system for yall, just paste this intro a script in ServerScriptService, if you notice any bugs or face problems, Js LMK!, this is the code.
showcase video:
(sorry for corrupted audio)
local CONFIG = {
LerpSpeed = 10, -- Speed of change of leg position
RaycastLength = 2, -- 2 is usually what you need for normal avatars
FootRaiseOffset = 0.02,
FootRaiseScale = 1.0, -- dont change or itll be weird or your leg will go thru the parts
RotationScale = 0.2, -- usually under 0.3 is good
MaxRaisePercent = 0.6, -- basically change it so your leg will only raise on parts thats size is 60% or smaller from your leg.
HipOffsetRight = CFrame.new( 1, -1, 0),
HipOffsetLeft = CFrame.new(-1, -1, 0),
RayDirection = Vector3.new(0, -2, 0),
}
local Wait = task.wait
local Spawn = task.spawn
local CFrameNew = CFrame.new
local CFrameAngles = CFrame.Angles
local V3 = Vector3.new
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local function FindChildOfClassAndName(parent, className, name)
if typeof(parent) ~= "Instance" then return end
for _, child in ipairs(parent:GetChildren()) do
if child:IsA(className) and child.Name == name then
return child
end
end
end
local function WaitForChildOfClassAndName(parent, className, name)
while Wait() do
local found = FindChildOfClassAndName(parent, className, name)
if found then return found end
end
end
local function GetParent(instance)
return typeof(instance) == "Instance" and instance.Parent
end
local function LerpJoint(joint, targetCFrame, speed)
if not GetParent(joint) then return end
if not joint:IsA("JointInstance") then return end
if typeof(targetCFrame) ~= "CFrame" then return end
if type(speed) ~= "number" then return end
joint.C0 = joint.C0:Lerp(targetCFrame, speed)
end
local function SetupCharacter(character)
local humanoidRootPart = WaitForChildOfClassAndName(character, "BasePart", "HumanoidRootPart")
local rightLeg = WaitForChildOfClassAndName(character, "BasePart", "Right Leg")
local leftLeg = WaitForChildOfClassAndName(character, "BasePart", "Left Leg")
local torso = WaitForChildOfClassAndName(character, "BasePart", "Torso")
local rightHip = WaitForChildOfClassAndName(torso, "JointInstance", "Right Hip")
local leftHip = WaitForChildOfClassAndName(torso, "JointInstance", "Left Hip")
local rightHipC0 = rightHip.C0
local leftHipC0 = leftHip.C0
local maxRaiseRight = rightLeg.Size.Y * CONFIG.MaxRaisePercent
local maxRaiseLeft = leftLeg.Size.Y * CONFIG.MaxRaisePercent
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = { character }
rayParams.FilterType = Enum.RaycastFilterType.Exclude
RunService.PreSimulation:Connect(function(deltaTime)
if not GetParent(character) or not GetParent(humanoidRootPart) then return end
local speed = deltaTime * CONFIG.LerpSpeed
local rootCFrame = humanoidRootPart.CFrame
local function worldRaiseToCFrame(raise)
local localUp = torso.CFrame:VectorToObjectSpace(V3(0, raise, 0))
return CFrameNew(localUp)
end
if rightLeg then
local origin = (rootCFrame * CONFIG.HipOffsetRight).Position
local rayResult = Workspace:Raycast(origin, CONFIG.RayDirection, rayParams)
if rayResult then
local dist = (rayResult.Distance - CONFIG.RaycastLength) - CONFIG.FootRaiseOffset
local raise = math.max(-dist, 0) * CONFIG.FootRaiseScale
local shift = math.max(dist, 0)
local angle = raise * CONFIG.RotationScale
if raise < maxRaiseRight then
LerpJoint(rightHip,
rightHipC0
* CFrameNew(-shift, 0, 0)
* worldRaiseToCFrame(raise)
* CFrameAngles(0, 0, angle),
speed)
else
LerpJoint(rightHip, rightHipC0, speed)
end
else
LerpJoint(rightHip, rightHipC0, speed)
end
end
if leftLeg then
local origin = (rootCFrame * CONFIG.HipOffsetLeft).Position
local rayResult = Workspace:Raycast(origin, CONFIG.RayDirection, rayParams)
if rayResult then
local dist = (rayResult.Distance - CONFIG.RaycastLength) - CONFIG.FootRaiseOffset
local raise = math.max(-dist, 0) * CONFIG.FootRaiseScale
local shift = math.max(dist, 0)
local angle = raise * CONFIG.RotationScale
if raise < maxRaiseLeft then
LerpJoint(leftHip,
leftHipC0
* CFrameNew(shift, 0, 0)
* worldRaiseToCFrame(raise)
* CFrameAngles(0, 0, -angle),
speed)
else
LerpJoint(leftHip, leftHipC0, speed)
end
else
LerpJoint(leftHip, leftHipC0, speed)
end
end
end)
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
Spawn(SetupCharacter, character)
end)
end)