#Need help with my script. Advanced MovementScript

5 messages · Page 1 of 1 (latest)

vale hedgeBOT
#

studio** You are now Level 3! **studio

torpid fable
#

local WALL_RUN_ANGLE = 80
local player =game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local JUMP_VELOCITY = math.sqrt(workspace.Gravity * humanoid.JumpHeight * 2)

#

local rootPart = nil
local debounce = false
local canWallRun = true
local isWallRunning = false
local isJumping = false
local isDoubleJumping = false
local counter = 1
local prevMoveDirection = humanoid.MoveDirection
local rootPart = character:WaitForChild("HumanoidRootPart")

#

function onMoveDirectionChanged(newMoveDirection)
if debounce then return end
debounce = true
task.wait(0.1)
debounce = false
if not isJumping and not isDoubleJumping then
local _, velocity = humanoid:GetVelocity()
local moveDirection = (velocity + newMoveDirection).Unit
local dot = moveDirection:Dot(rootPart.CFrame.UpVector)

    if not isWallRunning and canWallRun and dot < 0 and dot > -0.2 then
        local ray = Ray.new(rootPart.Position, moveDirection * 3)
        local part, position, normal = workspace:FindPartOnRayWithIgnoreList(ray, {rootPart,humanoid.Parent})
#
        if part and part.CanCollide then
            local angle = math.acos(normal:Dot(workspace.Gravity).Magnitude / normal.Magnitude) * (180 / math.pi)
            if angle <= WALL_RUN_ANGLE then
                isWallRunning = true
                canWallRun = false
                humanoid.WalkSpeed = humanoid.WalkSpeed * 1.5
                humanoid.JumpPower = humanoid.JumpPower * 1.5
                while isWallRunning and not isJumping and not isDoubleJumping do
                    local _, velocity = humanoid:GetVelocity()
                    humanoid:SetRootPartCFrame(CFrame.new(rootPart.Position, rootPart.Position + (moveDirection:Cross(normal).Unit * 3) - (normal * 1.5)))
                    humanoid:AddVelocity(workspace.Gravity * humanoid:GetMass())
                    task.wait()
                end
                humanoid.WalkSpeed = humanoid.WalkSpeed / 1.5
                humanoid.JumpPower = humanoid.JumpPower / 1.5
            end
        end
    end
end

end
game:GetService("RunService").RenderStepped:Connect(function()
if counter % 30 == 0 then
if humanoid.MoveDirection:Dot(humanoid.MoveDirection) > 0 then
if prevMoveDirection:Dot(humanoid.MoveDirection) < 0.5 then
onMoveDirectionChanged(humanoid.MoveDirection)
end
end
prevMoveDirection = humanoid.MoveDirection
end
counter = counter + 1
end)