Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ailenkai
- local keyframeSequenceProvider = game:GetService("KeyframeSequenceProvider")
- local playersService = game:GetService("Players")
- local userInputService = game:GetService("UserInputService")
- local replicatedStorage = game:GetService("ReplicatedStorage")
- local runService = game:GetService("RunService")
- local player = playersService.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid:Humanoid = character:WaitForChild("Humanoid")
- local root = character:WaitForChild("HumanoidRootPart")
- local camera = workspace.CurrentCamera
- local ball = character:WaitForChild("ball")
- local updateEvent = replicatedStorage:WaitForChild("update")
- camera.CameraType = Enum.CameraType.Custom
- humanoid.WalkSpeed = 50 -- Sets move speed
- local function lerp(from, to, alpha)
- return from + (to - from) * alpha
- end
- local currentMoveDirections = { W = false, A = false, S = false, D = false, Space = false }
- local function onInputBegan(input, gameProcessedEvent)
- if not gameProcessedEvent then
- local key = input.KeyCode.Name
- if currentMoveDirections[key] ~= nil then
- currentMoveDirections[key] = true
- end
- end
- end
- local function onInputEnded(input, gameProcessedEvent)
- if not gameProcessedEvent then
- local key = input.KeyCode.Name
- if currentMoveDirections[key] ~= nil then
- currentMoveDirections[key] = false
- end
- end
- end
- task.wait(1)
- local function createPreviewAnimation(keyframeSequence)
- local hashId = keyframeSequenceProvider:RegisterKeyframeSequence(keyframeSequence)
- local Animation = Instance.new("Animation")
- Animation.AnimationId = hashId
- return Animation
- end
- local animator = humanoid:FindFirstChildOfClass("Animator")
- local animation = ball:FindFirstChild(humanoid.RigType == Enum.HumanoidRigType.R15 and "R15ballRun" or "R6ballRun")
- local tempAnim = createPreviewAnimation(animation:FindFirstChildOfClass("KeyframeSequence"))
- local animationTrack = animator and animator:LoadAnimation(tempAnim)
- if animationTrack then
- animationTrack:Play()
- end
- local hasLandedRay = nil
- local isFalling = false
- local params = RaycastParams.new()
- params.FilterDescendantsInstances = {ball, character}
- params.FilterType = Enum.RaycastFilterType.Exclude
- local function onRenderStepped(deltaTime)
- if character and humanoid.Health > 0 then
- local speed = ball.AssemblyLinearVelocity.Magnitude
- local lookVectorX, lookVectorZ = camera.CFrame.LookVector.X, camera.CFrame.LookVector.Z
- local lookVector = Vector3.new(lookVectorX, 0, lookVectorZ).Unit
- local rightVector = lookVector:Cross(Vector3.new(0, 1, 0))
- local function calculateTargetMoveDirection()
- local moveDirection = Vector3.zero
- if currentMoveDirections.W then
- moveDirection = moveDirection + lookVector
- end
- if currentMoveDirections.S then
- moveDirection = moveDirection - lookVector
- end
- if currentMoveDirections.D then
- moveDirection = moveDirection + rightVector
- end
- if currentMoveDirections.A then
- moveDirection = moveDirection - rightVector
- end
- if moveDirection.Magnitude > 0 then
- moveDirection = moveDirection.Unit
- end
- return moveDirection
- end
- local targetMoveDirection = calculateTargetMoveDirection()
- if targetMoveDirection.Magnitude > 0 then
- ball.AssemblyLinearVelocity += targetMoveDirection * humanoid.WalkSpeed * deltaTime
- end
- hasLandedRay = workspace:Raycast(ball.Position, Vector3.new(0,-(ball.Size.Y + 0.1), 0), params)
- if hasLandedRay then
- isFalling = false
- else
- isFalling = true
- end
- if currentMoveDirections.Space and not isFalling then
- ball.AssemblyLinearVelocity += Vector3.new(0,5,0)
- end
- updateEvent:FireServer((humanoid.MoveDirection.Magnitude > 0.1) and humanoid.MoveDirection or root.AssemblyLinearVelocity)
- if animationTrack then
- animationTrack:AdjustSpeed(root.AssemblyLinearVelocity.Magnitude / humanoid.WalkSpeed)
- end
- end
- end
- userInputService.InputBegan:Connect(onInputBegan)
- userInputService.InputEnded:Connect(onInputEnded)
- runService.RenderStepped:Connect(onRenderStepped)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement