I have one more problem. I swear ill stop bugging you after this. Usually if you go too fast in different directions the legs will stay lifted and not react to the ground or whatever.
Script:
local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid : Humanoid = Character:FindFirstChild("Humanoid")
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local IKModule = require(game.ReplicatedStorage.Modules.IKModule)
local IKController = IKModule.New(Character)
local torsoSwing = 0
local side = false
local RlerpedFoot,LlerpedFoot = Vector3.new(), Vector3.new()
local LeftLegOffset = CFrame.new(-0.5, -3, 0)
local RightLegOffset = CFrame.new(0.5, -3, 0)
local torsoPosition : CFrame = Character:WaitForChild("Torso").CFrame
local rfplace, lfplace = (torsoPosition*RightLegOffset).Position, (torsoPosition*LeftLegOffset).Position
local params = RaycastParams.new()
params.FilterDescendantsInstances = {Character}
params.FilterType = Enum.RaycastFilterType.Exclude
humanoid.RootPart:WaitForChild("Running"):Destroy()
local Force
local Direction
local Value1
local Value2
local rootjoinc0 = humanoid.RootPart.RootJoint.C0
local raise
local raise2
game:GetService("RunService").RenderStepped:Connect(function(dt)
local ticknew = tick()
Character = player.Character or player.CharacterAdded:Wait()
local torsoPosition : CFrame = Character:WaitForChild("Torso").CFrame
local torso : BasePart = Character:WaitForChild("Torso")
local leftraycastdir = torso.AssemblyLinearVelocity + (torsoPosition.RightVector * -2) + (Vector3.new(0,-10,0) + torsoPosition.LookVector * 2)
local rightraycastdir = torso.AssemblyLinearVelocity + (torsoPosition.RightVector * 2) + (Vector3.new(0,-10,0) + torsoPosition.LookVector * 2)
local rightray = workspace:Raycast(humanoid.RootPart.Position, rightraycastdir,params)
local leftray = workspace:Raycast(humanoid.RootPart.Position, leftraycastdir,params)
local lastlfplace = lfplace
local lastrfplace = rfplace
local rayStandingRight = workspace:Raycast(Character['Right Leg'].Position, Character['Right Leg'].Position - lastrfplace, params)
local rayStandingLeft = workspace:Raycast(Character['Left Leg'].Position, Character['Left Leg'].Position - lastlfplace, params)
print(humanoid:GetState())
torsoSwing = math.sin(ticknew*Character.Humanoid.WalkSpeed)
humanoid.HipHeight = -.25
if humanoid.MoveDirection.Magnitude < 0.1 then
if rayStandingLeft then
lfplace = rayStandingLeft.Position
local distance = (Character['Left Leg'].Position - rayStandingLeft.Position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.lookAt(Character['Left Leg'].Position, rayStandingLeft.Position)*CFrame.new(0, 0, -distance/2)
end
if rayStandingRight then
rfplace = rayStandingRight.Position
end
if raise or raise2 then
raise = nil
raise2 = nil
end
--[[if then
rayStandingLeft = workspace:Raycast(torsoPosition.Position, leftstanddir ,params)
lfplace = rayStandingLeft.Position
end ]]
end
print(leftray.Distance)
if torsoSwing > 0 and side then
side = not side
--lfplace = (torsoPosition*LeftLegOffset).Position
if rightray and rightray.Instance and humanoid.MoveDirection.Magnitude > 0.1 then
rfplace = (rightray.Position)
local newfootstep = script.Footstep:Clone()
newfootstep.Parent = humanoid.RootPart
newfootstep.PlaybackSpeed = Random.new():NextNumber(.8, 1.2)
newfootstep:Play()
game.Debris:AddItem(newfootstep,newfootstep.TimeLength)
end
--game.TweenService:Create(humanoid.RootPart.RootJoint,TweenInfo.new(.1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{C0 = CFrame.Angles(math.rad(45),0,0)}):Play()
end
if torsoSwing < 0 and not side then
side = not side
--rfplace = (torsoPosition*RightLegOffset).Position
if leftray and leftray.Instance and humanoid.MoveDirection.Magnitude > 0.1 then
lfplace = (leftray.Position)
local newfootstep = script.Footstep:Clone()
newfootstep.Parent = humanoid.RootPart
newfootstep.PlaybackSpeed = Random.new():NextNumber(.8, 1.2)
newfootstep:Play()
game.Debris:AddItem(newfootstep,newfootstep.TimeLength)
end
--game.TweenService:Create(humanoid.RootPart.RootJoint,TweenInfo.new(.1,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{C0 = CFrame.Angles(math.rad(-45),0,0)}):Play()
end
RlerpedFoot = RlerpedFoot:Lerp(rfplace, math.min(1/0.075*dt, 1)/1.5)
LlerpedFoot = LlerpedFoot:Lerp(lfplace, math.min(1/0.075*dt, 1)/1.5)
raise = math.sin((RlerpedFoot - rfplace).magnitude/2.5)
raise2 = math.sin((LlerpedFoot - lfplace).magnitude/2.5)
IKController:LegIK("Left", LlerpedFoot + Vector3.new(0, (raise2/2), 0))
IKController:LegIK("Right", RlerpedFoot + Vector3.new(0, (raise/2), 0))
Force = humanoid.RootPart.AssemblyLinearVelocity * Vector3.new(1,0,1)
if Force.Magnitude > 2 then
Direction = Force.Unit
Value1 = humanoid.RootPart.CFrame.RightVector:Dot(Direction)
Value2 = humanoid.RootPart.CFrame.LookVector:Dot(Direction)
else
Value1 = 0
Value2 = 0
end
--humanoid.RootPart.RootJoint.C0 = humanoid.RootPart.RootJoint.C0:Lerp(rootjoinc0 * CFrame.Angles(math.rad(Value2 * 10), math.rad(-Value1 * 10), 0), 0.2)
end)