#Proedural animation bug

1 messages · Page 1 of 1 (latest)

regal rover
#

im trying to remake a part of cleaning simulator by Bribleco,but i cant get the procedural walking animation to work.
heres the main code (in the rig):

local ProceduralModule = require(/moduleLocation/.ProceduralModule)

local runService = game:GetService("RunService")

local enemy = script.Parent
local root = enemy:FindFirstChild("HumanoidRootPart")
local hum = enemy:FindFirstChild("Humanoid")

local target = workspace:FindFirstChild("Target")

--- Ik Targets yipee
local ikTargets = enemy:FindFirstChild("IkTargets")
local left_IkTarget = ikTargets:FindFirstChild("LeftIkTarget")
local right_IkTarget = ikTargets:FindFirstChild("RightIkTarget")

---Raycast parts
local raycastParts = enemy:FindFirstChild("RayCastParts")
local left_RaycastPart = raycastParts:FindFirstChild("LeftRaycastPart")
local right_RaycastPart = raycastParts:FindFirstChild("RightRaycastPart")

--- IKControls
local left_IkControl = hum:FindFirstChild("Left_IkControl")
local right_IkControl = hum:FindFirstChild("Right_IkControl")

left_IkControl.Pole = root.Left_Pole
right_IkControl.Pole = root.Right_Pole

local ProceduralModule = require(game:Getservice("ReplicatedStorage").ProceduralModule)

local rayCastParams = RaycastParams.new()
rayCastParams.FilterDescendantsInstances = {enemy}
rayCastParams.FilterType = Enum.RaycastFilterType.Exclude

while true do
    ProceduralModule:IkLegStep(left_IkTarget, left_RaycastPart , enemy.PrimaryPart, 2, 2, 1, 0.05, rayCastParams)
    task.wait(0.1)
    ProceduralModule:IkLegStep(right_IkTarget, right_RaycastPart, enemy.PrimaryPart, 2, 2, 1, 0.05, rayCastParams)
    task.wait(0.1)
end
#

also heres the procedural Module:

local ProceduralModule = {}


--// Returns a CFrame rotation between two vectors
--// Credit: @EgoMoose (Roblox)
function ProceduralModule:getRotationBetween(u, v)
    local randomAxis = Vector3.new(1, 0, 0)
    
    local dot = u:Dot(v)
    if (dot > 0.99999) then
        return CFrame.new()
        
    elseif (dot < -0.99999) then
        return CFrame.fromAxisAngle(randomAxis, math.pi)
    end
    
    return CFrame.fromAxisAngle(u:Cross(v), math.acos(dot))
end

function ProceduralModule:IkLegStep(ikTarget: BasePart, ikRayPart: BasePart, root: BasePart, stepDistance: number, stepForward: number, stepHeight: number, stepWait: number, rayCastParams: RaycastParams)
    stepWait = stepWait or 0.05
    stepForward = stepForward or 0
    stepHeight = stepHeight or 2
    
    local rayCast = workspace:Raycast(ikRayPart.Position, Vector3.new(0, -1000, 0), rayCastParams)
    
    if rayCast then
        if not ikTarget:GetAttribute("PreviousPos") then
            ikTarget:SetAttribute("PreviousPos", Vector3.new(0, 0, 0))
        end
        
        local previousFootPos = ikTarget:GetAttribute("PreviousPos")
        
        local defaultFootPos = rayCast.Position
        local diff = (defaultFootPos - previousFootPos).Magnitude
        
        --// Do a step
        if diff > stepDistance then
            local finalFootPos = rayCast.Position + root.CFrame.LookVector * stepForward
            local middleFootPos = ((finalFootPos - previousFootPos) * 0.5 + previousFootPos) + Vector3.new(0, stepHeight, 0)
            
            coroutine.wrap(function()
                ikTarget.Position = middleFootPos
                task.wait(stepWait)
                ikTarget.Position = finalFootPos
                
                ikTarget:SetAttribute("PreviousPos", ikTarget.Position)
            end)()
        end
    end
end

return ProceduralModule