Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TaskScheduler = {};
- PyramidCharacter = {};
- local RbxUtility = LoadLibrary("RbxUtility")
- local InsertService = game:service'InsertService'
- local RunService = game:service'RunService'
- local rbx_Wait = wait
- local rbx_ypcall = ypcall
- local threads, swapThreads = {}, {}
- local function StartCoroutine(func, delay, ...)
- if delay > 0 then
- rbx_Wait(delay)
- end
- local success, message = rbx_ypcall(func, ...)
- if not success then
- print("Error in a TaskScheduler coroutine: "..message)
- end
- end
- function TaskScheduler.GetCurrentTime()
- return currentTime
- end
- function TaskScheduler.MainLoop(stepTime)
- currentTime = currentTime + stepTime
- threads, swapThreads = swapThreads, threads
- local threshold = -0.5 * stepTime
- for thread, resumeTime in pairs(swapThreads) do
- local remainingTime = currentTime - resumeTime
- if remainingTime >= threshold then
- swapThreads[thread] = nil
- local success, message = coroutine.resume(thread, remainingTime, currentTime)
- if not success then
- print("Error in a TaskScheduler custom thread: "..message)
- end
- end
- end
- threads, swapThreads = swapThreads, threads
- for thread, resumeTime in pairs(swapThreads) do
- threads[thread], swapThreads[thread] = resumeTime, nil
- end
- end
- -- TODO: add stack trace info to scheduling functions?
- function TaskScheduler.Schedule(t, f, ...)
- coroutine.resume(coroutine.create(StartCoroutine), f, t, ...)
- end
- function TaskScheduler.Start(f, ...)
- coroutine.resume(coroutine.create(StartCoroutine), f, 0, ...)
- end
- function TaskScheduler.ScheduleCustomThread(t, f)
- threads[coroutine.create(f)] = currentTime + t
- end
- function TaskScheduler.Wait(duration)
- duration = tonumber(duration) or 0
- threads[coroutine.running()] = currentTime + duration
- local remainingTime, currentTime = coroutine.yield()
- return remainingTime + duration, currentTime
- end
- local Players=game.Players
- local success, player = Players.LocalPlayer
- if success and player then
- RunService.RenderStepped:connect(function()
- TaskScheduler.MainLoop(1 / 60)
- end)
- else
- RunService.Stepped:connect(function()
- TaskScheduler.MainLoop(1 / 30)
- end)
- end
- function TaskScheduler.Start(f, ...)
- coroutine.resume(coroutine.create(StartCoroutine), f, 0, ...)
- end
- local Camera = workspace.CurrentCamera or nil
- CharacterAppearance = {};
- CharacterAppearance.defaultAppearanceId = 2
- CharacterAppearance.stock = {}
- function CharacterAppearance.Create(properties)
- local id = properties.Id
- local bodyColors = Instance.new("BodyColors")
- bodyColors.HeadColor = properties.HeadColor
- bodyColors.TorsoColor = properties.TorsoColor
- bodyColors.RightArmColor = properties.RightArmColor
- bodyColors.LeftArmColor = properties.LeftArmColor
- bodyColors.RightLegColor = properties.RightLegColor
- bodyColors.LeftLegColor = properties.LeftLegColor
- local characterObjects = {bodyColors}
- local headObjects = {}
- local data = {
- characterObjects = characterObjects,
- headObjects = headObjects,
- tshirt = properties.TShirt
- }
- for _, assetId in ipairs(properties.CharacterAssets) do
- TaskScheduler.Start(CharacterAppearance.LoadAsset, characterObjects, assetId)
- end
- for _, assetId in ipairs(properties.HeadAssets) do
- TaskScheduler.Start(CharacterAppearance.LoadAsset, headObjects, assetId)
- end
- CharacterAppearance.stock[id] = data
- end
- function CharacterAppearance.GetDefaultAppearance()
- return CharacterAppearance.stock[CharacterAppearance.defaultAppearanceId]
- end
- function CharacterAppearance.LoadAsset(objects, assetId)
- local asset = InsertService:LoadAsset(assetId)
- for _, child in ipairs(asset:GetChildren()) do
- child.Archivable = true
- table.insert(objects, child:Clone())
- end
- end
- CharacterAppearance.Create {
- Id = 1,
- HeadColor = BrickColor.new("Institutional white"),
- TorsoColor = BrickColor.new("Institutional white"),
- RightArmColor = BrickColor.new("Institutional white"),
- LeftArmColor = BrickColor.new("Institutional white"),
- RightLegColor = BrickColor.new("Institutional white"),
- LeftLegColor = BrickColor.new("Institutional white"),
- CharacterAssets = {
- 90825058, 90825211,
- 27112056, 27112052,
- 27112039, 27112025,
- 27112068, 38322996
- },
- HeadAssets = {
- 20722130,
- 8330576
- }
- }
- CharacterAppearance.Create {
- Id = 2,
- HeadColor = BrickColor.new("Institutional white"),
- TorsoColor = BrickColor.new("Institutional white"),
- RightArmColor = BrickColor.new("Institutional white"),
- LeftArmColor = BrickColor.new("Institutional white"),
- RightLegColor = BrickColor.new("Institutional white"),
- LeftLegColor = BrickColor.new("Institutional white"),
- CharacterAssets = {
- 90825058, 90825211,
- 11748356, 1029025,
- 1235488, 27112056,
- 27112052, 27112039,
- 27112025, 27112068
- },
- HeadAssets = {
- 20722130
- }
- }
- CharacterAppearance.Create {
- Id = 3,
- HeadColor = BrickColor.new("Pastel brown"),
- TorsoColor = BrickColor.new("Pastel brown"),
- RightArmColor = BrickColor.new("Pastel brown"),
- LeftArmColor = BrickColor.new("Pastel brown"),
- RightLegColor = BrickColor.new("White"),
- LeftLegColor = BrickColor.new("White"),
- CharacterAssets = {
- 134289125, 48474356,
- 100339040, 46302558,
- 153955895
- },
- HeadAssets = {},
- TShirt = "rbxassetid://148856353"
- }
- CharacterAppearance.Create {
- Id = 4,
- HeadColor = BrickColor.new("Pastel brown"),
- TorsoColor = BrickColor.new("Pastel brown"),
- RightArmColor = BrickColor.new("Pastel brown"),
- LeftArmColor = BrickColor.new("Pastel brown"),
- RightLegColor = BrickColor.new("White"),
- LeftLegColor = BrickColor.new("White"),
- CharacterAssets = {
- 129458426, 96678344, 184489190
- },
- HeadAssets = {},
- TShirt = "rbxassetid://160146697"
- }
- function CharacterAppearance.GetDefaultAppearance()
- return CharacterAppearance.stock[CharacterAppearance.defaultAppearanceId]
- end
- PlayerControl = {};
- PlayerControl.fly_acceleration = 10
- PlayerControl.fly_basespeed = 250
- PlayerControl.fly_speed = PlayerControl.fly_basespeed
- PlayerControl.featherfallEnabled = true
- PlayerControl.pushable = false
- PlayerControl.rolling = false
- PlayerControl.rollingAngle = 0
- PlayerControl.rollingOffset = 0
- PlayerControl.rollingMaxOffset = 3
- PlayerControl.rollingSpeed = 1 / 50
- PlayerControl.characterEnabled = false
- PlayerControl.characterMode = "normal"
- local character = nil
- local flying, flyingMomentum, flyingTilt = false, Vector3.new(), 0
- local pose, regeneratingHealth, jumpDebounce = "Standing", false, false
- -- TODO: make local variables public
- local model, bodyColors, leftArmMesh, leftLegMesh, rightArmMesh, rightLegMesh, torsoMesh, wildcardHat, wildcardHandle, wildcardMesh, pants, shirt, humanoid,
- head, leftArm, leftLeg, rightArm, rightLeg, torso, rootPart, rootJoint, face, soundFreeFalling, soundGettingUp, soundRunning, leftHip, leftShoulder,
- rightHip, rightShoulder, neck, wildcardWeld, feetPart, feetWeld, feetTouchInterest, bodyGyro, bodyVelocity, headMesh, torsoLight
- local AnimateCharacter
- local UserInterface = game:service'UserInputService'
- local chatBubbles = {}
- local chatCharacterLimit = 240
- function PlayerControl.CreateCharacter()
- local characterMode = PlayerControl.characterMode
- if characterMode == "normal" then
- if not PlayerControl.characterEnabled then
- return
- end
- local appearance = CharacterAppearance.GetDefaultAppearance()
- local active = true
- local torsoCFrame = (torso and torso.CFrame) or PlayerControl.torso_cframe or CFrame.new(0, 10, 0)
- if torsoCFrame.p.Y < -450 then
- torsoCFrame = CFrame.new(0, 10, 0)
- end
- local rootPartCFrame = (rootPart and rootPart.CFrame) or PlayerControl.torso_cframe or CFrame.new(0, 10, 0)
- if rootPartCFrame.p.Y < -450 then
- rootPartCFrame = CFrame.new(0, 10, 0)
- end
- local cameraCFrame = Camera.CoordinateFrame
- local connections = {}
- local feetTouching = {}
- local previousWalkSpeed = 0
- local prevLeftHip, prevLeftShoulder, prevRightHip, prevRightShoulder = leftHip, leftShoulder, rightHip, rightShoulder
- model = Instance.new("Model")
- humanoid = Instance.new("Humanoid", model)
- head = Instance.new("Part", model)
- leftArm = Instance.new("Part", model)
- leftLeg = Instance.new("Part", model)
- rightArm = Instance.new("Part", model)
- rightLeg = Instance.new("Part", model)
- torso = Instance.new("Part", model)
- rootPart = Instance.new("Part", model)
- soundFallingDown = Instance.new("Sound", head)
- soundFreeFalling = Instance.new("Sound", head)
- soundGettingUp = Instance.new("Sound", head)
- soundJumping = Instance.new("Sound", head)
- soundRunning = Instance.new("Sound", head)
- leftHip = Instance.new("Motor", torso)
- leftShoulder = Instance.new("Motor", torso)
- rightHip = Instance.new("Motor", torso)
- rightShoulder = Instance.new("Motor", torso)
- neck = Instance.new("Motor", torso)
- rootJoint = Instance.new("Motor", rootPart)
- feetPart = Instance.new("Part", model)
- feetWeld = Instance.new("Weld", torso)
- bodyGyro = Instance.new("BodyGyro", rootPart)
- bodyVelocity = Instance.new("BodyVelocity", rootPart)
- model.Archivable = false
- local user_name=game.Players.LocalPlayer.Name
- local Player=game.Players.LocalPlayer
- model.Name = user_name or Player.Name
- model.PrimaryPart = head
- humanoid.LeftLeg = leftLeg
- humanoid.RightLeg = rightLeg
- humanoid.Torso = rootPart
- head.CFrame = torsoCFrame * CFrame.new(0, 1.5, 0)
- head.FormFactor = "Symmetric"
- head.Locked = true
- head.Name = "Head"
- head.Size = Vector3.new(2, 1, 1)
- head.TopSurface = "Smooth"
- leftArm.CanCollide = false
- leftArm.CFrame = torsoCFrame * CFrame.new(-1.5, 0, 0)
- leftArm.FormFactor = "Symmetric"
- leftArm.Locked = true
- leftArm.Name = "Left Arm"
- leftArm.Size = Vector3.new(1, 2, 1)
- leftLeg.BottomSurface = "Smooth"
- leftLeg.CanCollide = false
- leftLeg.CFrame = torsoCFrame * CFrame.new(-0.5, -2, 0)
- leftLeg.FormFactor = "Symmetric"
- leftLeg.Locked = true
- leftLeg.Name = "Left Leg"
- leftLeg.Size = Vector3.new(1, 2, 1)
- leftLeg.TopSurface = "Smooth"
- rightArm.CanCollide = false
- rightArm.CFrame = torsoCFrame * CFrame.new(1.5, 0, 0)
- rightArm.FormFactor = "Symmetric"
- rightArm.Locked = true
- rightArm.Name = "Right Arm"
- rightArm.Size = Vector3.new(1, 2, 1)
- rightLeg.BottomSurface = "Smooth"
- rightLeg.CanCollide = false
- rightLeg.CFrame = torsoCFrame * CFrame.new(0.5, -2, 0)
- rightLeg.FormFactor = "Symmetric"
- rightLeg.Locked = true
- rightLeg.Name = "Right Leg"
- rightLeg.Size = Vector3.new(1, 2, 1)
- rightLeg.TopSurface = "Smooth"
- torso.CFrame = torsoCFrame
- torso.FormFactor = "Symmetric"
- torso.LeftSurface = "Weld"
- torso.Locked = true
- torso.RightSurface = "Weld"
- torso.Name = "Torso"
- torso.Size = Vector3.new(2, 2, 1)
- rootPart.BottomSurface = "Smooth"
- rootPart.BrickColor = BrickColor.Blue()
- rootPart.CFrame = rootPartCFrame
- rootPart.FormFactor = "Symmetric"
- rootPart.LeftSurface = "Weld"
- rootPart.Locked = true
- rootPart.RightSurface = "Weld"
- rootPart.Name = "HumanoidRootPart"
- rootPart.Size = Vector3.new(2, 2, 1)
- rootPart.TopSurface = "Smooth"
- rootPart.Transparency = 1
- soundFreeFalling.Archivable = false
- soundFreeFalling.SoundId = "rbxasset://sounds/swoosh.wav"
- soundGettingUp.Archivable = false
- soundGettingUp.SoundId = "rbxasset://sounds/hit.wav"
- soundRunning.Archivable = false
- soundRunning.SoundId = "rbxasset://sounds/bfsl-minifigfoots1.mp3"
- soundRunning.Looped = true
- leftHip.C0 = CFrame.new(-1, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- leftHip.C1 = CFrame.new(-0.5, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- leftHip.MaxVelocity = 0.1
- leftHip.Name = "Left Hip"
- leftHip.Part0 = torso
- leftHip.Part1 = leftLeg
- leftShoulder.C0 = CFrame.new(-1, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- leftShoulder.C1 = CFrame.new(0.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
- leftShoulder.MaxVelocity = 0.15
- leftShoulder.Name = "Left Shoulder"
- leftShoulder.Part0 = torso
- leftShoulder.Part1 = leftArm
- rightHip.C0 = CFrame.new(1, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- rightHip.C1 = CFrame.new(0.5, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- rightHip.MaxVelocity = 0.1
- rightHip.Name = "Right Hip"
- rightHip.Part0 = torso
- rightHip.Part1 = rightLeg
- rightShoulder.C0 = CFrame.new(1, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- rightShoulder.C1 = CFrame.new(-0.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
- rightShoulder.MaxVelocity = 0.15
- rightShoulder.Name = "Right Shoulder"
- rightShoulder.Part0 = torso
- rightShoulder.Part1 = rightArm
- if prevLeftHip then
- leftHip.CurrentAngle = prevLeftHip.CurrentAngle
- leftHip.DesiredAngle = prevLeftHip.DesiredAngle
- end
- if prevLeftShoulder then
- leftShoulder.CurrentAngle = prevLeftShoulder.CurrentAngle
- leftShoulder.DesiredAngle = prevLeftShoulder.DesiredAngle
- end
- if prevRightHip then
- rightHip.CurrentAngle = prevRightHip.CurrentAngle
- rightHip.DesiredAngle = prevRightHip.DesiredAngle
- end
- if prevRightShoulder then
- rightShoulder.CurrentAngle = prevRightShoulder.CurrentAngle
- rightShoulder.DesiredAngle = prevRightShoulder.DesiredAngle
- end
- neck.C0 = CFrame.new(0, 1, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
- neck.C1 = CFrame.new(0, -0.5, 0, -1, -0, -0, 0, 0, 1, 0, 1, 0)
- neck.Name = "Neck"
- neck.Part0 = torso
- neck.Part1 = head
- rootJoint.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
- rootJoint.C1 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
- rootJoint.Name = "RootJoint"
- rootJoint.Part0 = rootPart
- rootJoint.Part1 = torso
- feetPart.BottomSurface = "Smooth"
- feetPart.CanCollide = false
- feetPart.CFrame = torsoCFrame * CFrame.new(0, -3.1, 0)
- feetPart.FormFactor = "Custom"
- feetPart.Locked = true
- feetPart.Name = "Platform"
- feetPart.Size = Vector3.new(1.8, 0.2, 0.8)
- feetPart.TopSurface = "Smooth"
- feetPart.Transparency = 1
- feetWeld.C0 = CFrame.new(0, -3, 0)
- feetWeld.C1 = CFrame.new(0, 0.1, 0)
- feetWeld.Name = "PlatformWeld"
- feetWeld.Part0 = torso
- feetWeld.Part1 = feetPart
- table.insert(connections, feetPart.Touched:connect(function(hit)
- feetTouching[hit] = true
- end))
- table.insert(connections, feetPart.TouchEnded:connect(function(hit)
- feetTouching[hit] = nil
- end))
- feetTouchInterest = feetPart:FindFirstChild("TouchInterest")
- bodyGyro.D = 3250
- bodyGyro.P = 400000
- bodyGyro.maxTorque = Vector3.new(1000000000, 0, 1000000000)
- bodyVelocity.P = 5000
- bodyVelocity.maxForce = Vector3.new(0, 0, 0)
- bodyVelocity.velocity = Vector3.new(0, 0, 0)
- torsoLight = Instance.new("PointLight", torso)
- torsoLight.Brightness = 0.4
- torsoLight.Color = Color3.new(1, 1, 1)
- torsoLight.Range = 16
- torsoLight.Shadows = true
- local ff1, ff2, ff3, ff4, ff5, ff6, ff7, ff8, ff9 = Instance.new("ForceField", head), Instance.new("ForceField", leftArm), Instance.new("ForceField", leftLeg), Instance.new("ForceField", rightArm), Instance.new("ForceField", rightLeg), Instance.new("ForceField", torso), Instance.new("ForceField", wildcardHandle), Instance.new("ForceField", feetPart), Instance.new("ForceField", rootPart)
- local forcefields = {[ff1] = head, [ff2] = leftArm, [ff3] = leftLeg, [ff4] = rightArm, [ff5] = rightLeg, [ff6] = torso, [ff7] = wildcardHandle, [ff8] = feetPart, [ff9] = rootPart}
- local objects = {[humanoid] = true, [head] = true, [leftArm] = true, [leftLeg] = true, [rightArm] = true, [rightLeg] = true, [torso] = true, [rootPart] = true, [rootJoint] = true, [soundFreeFalling] = true, [soundGettingUp] = true, [soundRunning] = true, [leftHip] = true, [leftShoulder] = true, [rightHip] = true, [rightShoulder] = true, [neck] = true, [feetPart] = true, [feetWeld] = true, [feetTouchInterest] = true, [bodyGyro] = true, [bodyVelocity] = true, [ff1] = true, [ff2] = true, [ff3] = true, [ff4] = true, [ff5] = true, [ff6] = true, [ff7] = true, [ff8] = true, [ff9] = true}
- local tshirtUrl = appearance.tshirt
- if tshirtUrl then
- local tshirt = Instance.new("Decal", torso)
- tshirt.Name = "roblox"
- tshirt.Texture = tshirtUrl
- objects[tshirt] = true
- end
- for _, template in ipairs(appearance.characterObjects) do
- local object = template:Clone()
- local newObjects = {object}
- for _, object in ipairs(newObjects) do
- objects[object] = true
- for _, child in ipairs(object:GetChildren()) do
- table.insert(newObjects, child)
- end
- end
- if object:IsA("BodyColors") then
- head.BrickColor = object.HeadColor
- leftArm.BrickColor = object.LeftArmColor
- leftLeg.BrickColor = object.LeftLegColor
- rightArm.BrickColor = object.RightArmColor
- rightLeg.BrickColor = object.RightLegColor
- torso.BrickColor = object.TorsoColor
- elseif object:IsA("Hat") then
- local handle = object:FindFirstChild("Handle")
- if handle and handle:IsA("BasePart") then
- local weld = Instance.new("Weld", head)
- weld.C0 = CFrame.new(0, 0.5, 0)
- local attachmentPos = object.AttachmentPos
- local attachmentRight = object.AttachmentRight
- local attachmentUp = object.AttachmentUp
- local attachmentForward = object.AttachmentForward
- weld.C1 = CFrame.new(attachmentPos.X, attachmentPos.Y, attachmentPos.Z,
- attachmentRight.X, attachmentUp.X, -attachmentForward.X,
- attachmentRight.Y, attachmentUp.Y, -attachmentForward.Y,
- attachmentRight.Z, attachmentUp.Z, -attachmentForward.Z)
- weld.Name = "HeadWeld"
- weld.Part0 = head
- weld.Part1 = handle
- handle.Parent = model
- local antiGravity = Instance.new("BodyForce", handle)
- antiGravity.force = Vector3.new(0, handle:GetMass() * 196.2, 0)
- objects[object] = false
- object.Parent = nil
- objects[weld] = true
- end
- end
- object.Parent = model
- end
- local facePresent = false
- local headMeshPresent = false
- for _, template in ipairs(appearance.headObjects) do
- local object = template:Clone()
- local newObjects = {object}
- for _, object in ipairs(newObjects) do
- objects[object] = true
- for _, child in ipairs(object:GetChildren()) do
- table.insert(newObjects, child)
- end
- end
- if object:IsA("DataModelMesh") then
- headMeshPresent = true
- elseif object:IsA("Decal") then
- facePresent = true
- end
- object.Parent = head
- end
- if not facePresent then
- local face = Instance.new("Decal", head)
- face.Texture = "rbxasset://textures/face.png"
- objects[face] = true
- end
- if not headMeshPresent then
- local headMesh = Instance.new("SpecialMesh", head)
- headMesh.Scale = Vector3.new(1.25, 1.25, 1.25)
- objects[headMesh] = true
- end
- table.insert(connections, model.DescendantAdded:connect(function(object)
- local success, is_localscript = pcall(game.IsA, object, "LocalScript")
- if success and is_localscript then
- pcall(Utility.SetProperty, object, "Disabled", true)
- local changed_connection = pcall(object.Changed.connect, object.Changed, function(property)
- if property == "Disabled" and not object.Disabled then
- pcall(Utility.SetProperty, object, "Disabled", true)
- object:Destroy()
- end
- end)
- end
- if not objects[object] then
- object:Destroy()
- end
- end))
- model.Parent = workspace
- Player.Character = model
- Camera.CameraSubject = humanoid
- Camera.CameraType = "Track"
- Camera.CoordinateFrame = cameraCFrame
- local IsStanding
- local RegenerateHealth
- local ResetCharacter
- function IsStanding()
- return not not next(feetTouching)
- end
- function RegenerateHealth()
- if humanoid.Health < 1 then
- humanoid.Health = 100
- elseif not regeneratingHealth then
- regeneratingHealth = true
- local elapsedTime = wait(1)
- regeneratingHealth = false
- if humanoid.Health < 100 then
- humanoid.Health = math.min(humanoid.Health + elapsedTime, 100)
- end
- end
- end
- function ResetCharacter()
- for index, connection in ipairs(connections) do
- connection:disconnect()
- end
- active = false
- end
- table.insert(connections, model.AncestryChanged:connect(ResetCharacter))
- table.insert(connections, model.DescendantRemoving:connect(function(object)
- local parent = forcefields[object]
- if parent then
- forcefields[object] = nil
- local new_forcefield = Instance.new("ForceField")
- forcefields[new_forcefield] = parent
- objects[new_forcefield] = true
- new_forcefield.Parent = parent
- elseif objects[object] then
- ResetCharacter()
- end
- end))
- table.insert(connections, humanoid.HealthChanged:connect(RegenerateHealth))
- table.insert(connections, humanoid.Climbing:connect(function() pose = "Climbing" end))
- table.insert(connections, humanoid.FallingDown:connect(function(state) pose = "FallingDown" end))
- table.insert(connections, humanoid.FreeFalling:connect(function(state) pose = "FreeFall" if state then soundFreeFalling:Play() else
- soundFreeFalling:Pause() end end))
- table.insert(connections, humanoid.GettingUp:connect(function(state) pose = "GettingUp" if state then soundGettingUp:Play() else
- soundGettingUp:Pause() end end))
- table.insert(connections, humanoid.PlatformStanding:connect(function() pose = "PlatformStanding" end))
- table.insert(connections, humanoid.Seated:connect(function() pose = "Seated" end))
- table.insert(connections, humanoid.Swimming:connect(function(speed) if speed > 0 then pose = "Swimming" else pose = "Standing" end end))
- local previousRootPartCFrame = rootPart.CFrame
- TaskScheduler.Start(function()
- while active do
- local totalTime = TaskScheduler.GetCurrentTime()
- local stepTime = 1 / 60
- if not PlayerControl.characterEnabled then
- ResetCharacter()
- break
- end
- torsoLight.Brightness = 0.5 + 0.15 * math.sin(totalTime * 0.75 * math.pi)
- local featherfallEnabled = PlayerControl.IsFeatherfallEnabled()
- local rootPartCFrame = rootPart.CFrame
- if not jumpDebounce and UserInterface:IsKeyDown(Enum.KeyCode.Space) then
- if humanoid.Sit then
- humanoid.Sit = false
- end
- if IsStanding() then
- jumpDebounce = true
- pose = "Jumping"
- rootPart.Velocity = Vector3.new(rootPart.Velocity.X, 50, rootPart.Velocity.Z)
- torso.Velocity = Vector3.new(torso.Velocity.X, 50, torso.Velocity.Z)
- TaskScheduler.Schedule(1, function()
- if pose == "Jumping" then
- pose = "FreeFall"
- end
- jumpDebounce = false
- humanoid.Jump = false
- end)
- end
- end
- local cameraCFrame = Camera.CoordinateFrame
- local cameraDirection = cameraCFrame.lookVector
- if flying then
- if PlayerControl.rolling then
- local rootPartCFrame = rootPart.CFrame
- local speed = (rootPartCFrame - rootPartCFrame.p):pointToObjectSpace(rootPart.Velocity).Y
- local decay = 0.5 ^ stepTime
- if math.abs(speed) <= 50 then
- PlayerControl.rollingAngle = (((PlayerControl.rollingAngle + 0.5) % 1 - 0.5) * decay) % 1
- PlayerControl.rollingOffset = PlayerControl.rollingOffset * decay
- else
- PlayerControl.rollingAngle = (PlayerControl.rollingAngle + stepTime * speed * PlayerControl.rollingSpeed) % 1
- PlayerControl.rollingOffset = (PlayerControl.rollingOffset + PlayerControl.rollingMaxOffset * (1 / decay - 1)) * decay
- end
- rootJoint.C0 = (CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0) * CFrame.Angles(PlayerControl.rollingAngle * 2 * math.pi, 0, 0)) * CFrame.new(0, -PlayerControl.rollingOffset, 0)
- else
- rootJoint.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
- PlayerControl.rollingAngle = 0
- PlayerControl.rollingOffset = 0
- end
- rightShoulder.MaxVelocity = 0.5
- leftShoulder.MaxVelocity = 0.5
- rightShoulder.DesiredAngle = 0
- leftShoulder.DesiredAngle = 0
- rightHip.DesiredAngle = 0
- leftHip.DesiredAngle = 0
- bodyGyro.D = 500
- bodyGyro.P = 1e6
- bodyGyro.maxTorque = Vector3.new(1e6, 1e6, 1e6)
- bodyVelocity.P = 1250
- bodyVelocity.maxForce = Vector3.new(1e6, 1e6, 1e6)
- local movementRight = 0
- local movementForward = 0
- local movementUp = 0
- if UserInterface:IsKeyDown(Enum.KeyCode.A) and not UserInterface:IsKeyDown(Enum.KeyCode.D) then
- movementRight = -1
- elseif UserInterface:IsKeyDown(Enum.KeyCode.D) then
- movementRight = 1
- end
- if UserInterface:IsKeyDown(Enum.KeyCode.W) then
- movementUp = 0.2
- if not UserInterface:IsKeyDown(Enum.KeyCode.S) then
- movementForward = -1
- end
- elseif UserInterface:IsKeyDown(Enum.KeyCode.S) then
- movementForward = 1
- end
- local movement = PlayerControl.fly_acceleration * cameraCFrame:vectorToWorldSpace(Vector3.new(movementRight, movementUp, movementForward))
- local previousMomentum = flyingMomentum
- local previousTilt = flyingTilt
- flyingMomentum = movement + flyingMomentum * (1 - PlayerControl.fly_acceleration / PlayerControl.fly_speed)
- flyingTilt = ((flyingMomentum * Vector3.new(1, 0, 1)).unit:Cross((previousMomentum * Vector3.new(1, 0, 1)).unit)).Y
- if flyingTilt ~= flyingTilt or flyingTilt == math.huge then
- flyingTilt = 0
- end
- local absoluteTilt = math.abs(flyingTilt)
- if absoluteTilt > 0.06 or absoluteTilt < 0.0001 then
- if math.abs(previousTilt) > 0.0001 then
- flyingTilt = previousTilt * 0.9
- else
- flyingTilt = 0
- end
- else
- flyingTilt = previousTilt * 0.77 + flyingTilt * 0.25
- end
- previousTilt = flyingTilt
- if flyingMomentum.magnitude < 0.1 then
- flyingMomentum = Vector3.new(0, 0, 0)
- -- bodyGyro.cframe = cameraCFrame
- else
- local momentumOrientation = CFrame.new(Vector3.new(0, 0, 0), flyingMomentum)
- local tiltOrientation = CFrame.Angles(0, 0, -20 * flyingTilt)
- bodyGyro.cframe = momentumOrientation * tiltOrientation * CFrame.Angles(-0.5 * math.pi * math.min(flyingMomentum.magnitude / PlayerControl.fly_speed, 1), 0, 0)
- end
- bodyVelocity.velocity = flyingMomentum + Vector3.new(0, 0.15695775618683547, 0)
- rootPart.Velocity = flyingMomentum
- previousMomentum = flyingMomentum
- else
- rootJoint.C0 = CFrame.new(0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 1, 0)
- PlayerControl.rollingAngle = 0
- PlayerControl.rollingOffset = 0
- bodyGyro.D = 3250
- bodyGyro.P = 400000
- bodyVelocity.P = 5000
- local cameraDirection = cameraCFrame.lookVector
- local walkDirection = Vector3.new(0, 0, 0)
- local walkSpeed = 16
- if UserInterface:IsKeyDown(Enum.KeyCode.W) then
- if UserInterface:IsKeyDown(Enum.KeyCode.A) then
- walkDirection = Vector3.new(cameraDirection.X + cameraDirection.Z, 0, cameraDirection.Z - cameraDirection.X).unit
- elseif UserInterface:IsKeyDown(Enum.KeyCode.D) then
- walkDirection = Vector3.new(cameraDirection.X - cameraDirection.Z, 0, cameraDirection.Z + cameraDirection.X).unit
- else
- walkDirection = Vector3.new(cameraDirection.X, 0, cameraDirection.Z).unit
- end
- elseif UserInterface:IsKeyDown(Enum.KeyCode.S) then
- if UserInterface:IsKeyDown(Enum.KeyCode.A) then
- walkDirection = Vector3.new(-cameraDirection.X + cameraDirection.Z, 0, -cameraDirection.Z - cameraDirection.X).unit
- elseif UserInterface:IsKeyDown(Enum.KeyCode.D) then
- walkDirection = Vector3.new(-cameraDirection.X - cameraDirection.Z, 0, -cameraDirection.Z + cameraDirection.X).unit
- else
- walkDirection = Vector3.new(-cameraDirection.X, 0, -cameraDirection.Z).unit
- end
- elseif UserInterface:IsKeyDown(Enum.KeyCode.A) then
- walkDirection = Vector3.new(cameraDirection.Z, 0, -cameraDirection.X).unit
- elseif UserInterface:IsKeyDown(Enum.KeyCode.D) then
- walkDirection = Vector3.new(-cameraDirection.Z, 0, cameraDirection.X).unit
- else
- walkSpeed = 0
- end
- if walkSpeed ~= previousWalkSpeed then
- if walkSpeed > 0 then
- soundRunning:Play()
- else
- soundRunning:Pause()
- end
- end
- if walkSpeed > 0 then
- if pose ~= "Jumping" then
- if IsStanding() then
- pose = "Running"
- else
- pose = "FreeFall"
- end
- end
- bodyGyro.cframe = CFrame.new(Vector3.new(), walkDirection)
- bodyGyro.maxTorque = Vector3.new(1000000000, 1000000000, 1000000000)
- bodyVelocity.maxForce = Vector3.new(1000000, maxForceY, 1000000)
- else
- if pose ~= "Jumping" then
- if IsStanding() then
- pose = "Standing"
- else
- pose = "FreeFall"
- end
- end
- -- TODO: find and fix bug that causes torso to rotate back to some angle
- bodyGyro.maxTorque = Vector3.new(1000000000, 1000000000, 1000000000) -- Vector3.new(1000000000, 0, 1000000000)
- if PlayerControl.pushable then
- bodyVelocity.maxForce = Vector3.new(0, 0, 0)
- else
- bodyVelocity.maxForce = Vector3.new(1000000, 0, 1000000)
- end
- end
- if featherfallEnabled then
- local velocity = rootPart.Velocity
- if velocity.Y > 50 then
- rootPart.Velocity = Vector3.new(velocity.X, 50, velocity.Z)
- elseif velocity.Y < -50 then
- rootPart.Velocity = Vector3.new(velocity.X, -50, velocity.Z)
- end
- local distanceVector = rootPartCFrame.p - previousRootPartCFrame.p
- local offsetX, offsetY, offsetZ = distanceVector.X, distanceVector.Y, distanceVector.Z
- local MAX_MOVEMENT = 50 * 0.03333333507180214
- if offsetX > MAX_MOVEMENT then
- offsetX = MAX_MOVEMENT
- elseif offsetX < -MAX_MOVEMENT then
- offsetX = -MAX_MOVEMENT
- end
- if offsetY > MAX_MOVEMENT then
- offsetY = MAX_MOVEMENT
- elseif offsetY < -MAX_MOVEMENT then
- offsetY = -MAX_MOVEMENT
- end
- if offsetZ > MAX_MOVEMENT then
- offsetZ = MAX_MOVEMENT
- elseif offsetZ < -MAX_MOVEMENT then
- offsetZ = -MAX_MOVEMENT
- end
- local offset = Vector3.new(offsetX, offsetY, offsetZ)
- if offset ~= distanceVector then
- rootPartCFrame = previousRootPartCFrame + offset
- --rootPart.CFrame = rootPartCFrame
- end
- end
- local walkingVelocity = walkDirection * walkSpeed
- bodyVelocity.velocity = walkingVelocity
- if not jumpDebounce and math.abs(rootPart.Velocity.Y) <= 0.1 then
- rootPart.Velocity = Vector3.new(walkingVelocity.X, rootPart.Velocity.Y, walkingVelocity.Z)
- end
- previousWalkSpeed = walkSpeed
- if pose == "Jumping" or jumpDebounce then
- rightShoulder.MaxVelocity = 0.5
- leftShoulder.MaxVelocity = 0.5
- rightShoulder.DesiredAngle = 3.14
- leftShoulder.DesiredAngle = -3.14
- rightHip.DesiredAngle = 0
- leftHip.DesiredAngle = 0
- elseif pose == "FreeFall" then
- rightShoulder.MaxVelocity = 0.5
- leftShoulder.MaxVelocity = 0.5
- rightShoulder.DesiredAngle = 3.14
- leftShoulder.DesiredAngle = -3.14
- rightHip.DesiredAngle = 0
- leftHip.DesiredAngle = 0
- elseif pose == "Seated" then
- rightShoulder.MaxVelocity = 0.15
- leftShoulder.MaxVelocity = 0.15
- rightShoulder.DesiredAngle = 3.14 / 2
- leftShoulder.DesiredAngle = -3.14 / 2
- rightHip.DesiredAngle = 3.14 / 2
- leftHip.DesiredAngle = -3.14 / 2
- else
- local climbFudge = 0
- local amplitude
- local frequency
- if pose == "Running" then
- rightShoulder.MaxVelocity = 0.15
- leftShoulder.MaxVelocity = 0.15
- amplitude = 1
- frequency = 9
- elseif (pose == "Climbing") then
- rightShoulder.MaxVelocity = 0.5
- leftShoulder.MaxVelocity = 0.5
- amplitude = 1
- frequency = 9
- climbFudge = 3.14
- else
- amplitude = 0.1
- frequency = 1
- end
- local desiredAngle = amplitude * math.sin(totalTime * frequency)
- rightShoulder.DesiredAngle = desiredAngle + climbFudge
- leftShoulder.DesiredAngle = desiredAngle - climbFudge
- rightHip.DesiredAngle = -desiredAngle
- leftHip.DesiredAngle = -desiredAngle
- end
- end
- previousRootPartCFrame = rootPartCFrame
- RunService.RenderStepped:wait()
- end
- if model.Parent ~= nil then
- model.Parent = nil
- end
- PlayerControl.CreateCharacter()
- end)
- humanoid.Health = 100
- character = model
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement