Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Tool = Instance.new("Tool")
- Tool.Name = "Ball"
- Tool.RequiresHandle = false
- Tool.CanBeDropped = false
- Tool.Parent = owner.Backpack
- local ls = NLS([[
- local Tool = script:WaitForChild("ToolPointer").Value
- local Ball = Tool:WaitForChild("Ball")
- local Weld,Humanoid
- local RS = game:GetService("RunService")
- local ControlModule = require(game:GetService("Players").LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")).controls
- local cam = workspace.CurrentCamera
- workspace:GetPropertyChangedSignal("CurrentCamera"):Connect(function()
- cam = workspace.CurrentCamera
- end)
- local CameraAngleUpdateConnection
- local AnimPlayedConnection
- local bf = Instance.new("BodyForce")
- bf.Parent = Ball
- local function calculateRawMoveVector(cameraRelativeMoveVector)
- if not cam then
- return cameraRelativeMoveVector
- end
- local c, s
- local _, _, _, R00, R01, R02, _, _, R12, _, _, R22 = cam.CFrame:GetComponents()
- if R12 < 1 and R12 > -1 then
- -- X and Z components from back vector.
- c = R22
- s = R02
- else
- -- In this case the camera is looking straight up or straight down.
- -- Use X components from right and up vectors.
- c = R00
- s = -R01*math.sign(R12)
- end
- local norm = math.sqrt(c*c + s*s)
- return Vector3.new(
- (c*cameraRelativeMoveVector.x + s*cameraRelativeMoveVector.z)/norm,
- 0,
- (c*cameraRelativeMoveVector.z - s*cameraRelativeMoveVector.x)/norm
- )
- end
- local force = 10000
- local jumped = false
- local function UpdateCameraAngle()
- if not ControlModule.activeController then
- bf.Force = Vector3.new(0,0,0)
- end
- local MoveVector = ControlModule.activeController:GetMoveVector()
- local CameraRelative = ControlModule.activeController:IsMoveVectorCameraRelative()
- local isJumping = ControlModule.activeController:GetIsJumping()
- if not jumped and isJumping then
- jumped = true
- Ball:ApplyImpulse(Vector3.new(0,10000,0))
- else
- jumped = false
- end
- if CameraRelative then
- MoveVector = calculateRawMoveVector(MoveVector)
- end
- bf.Force = MoveVector * force
- end
- local function AnimationPlayed(anim)
- anim:Stop()
- end
- local function UnequipTool()
- if Weld then
- Weld:Destroy()
- Weld = nil
- end
- if Humanoid then
- Humanoid:ChangeState(Enum.HumanoidStateType.FallingDown)
- Humanoid = nil
- end
- if CameraAngleUpdateConnection then
- CameraAngleUpdateConnection:Disconnect()
- CameraAngleUpdateConnection = nil
- end
- if AnimPlayedConnection then
- AnimPlayedConnection:Disconnect()
- AnimPlayedConnection = nil
- end
- end
- local function EquipTool()
- local Character = Tool.Parent
- local HRP = Character:FindFirstChild("HumanoidRootPart")
- local hum = Character:FindFirstChild("Humanoid")
- if not HRP or not hum then return end
- Ball.CFrame = HRP.CFrame
- Ball.AssemblyLinearVelocity = HRP.AssemblyLinearVelocity
- Ball.AssemblyAngularVelocity = HRP.AssemblyAngularVelocity
- Weld = Instance.new("Weld")
- Weld.Part0 = HRP
- Weld.Part1 = Ball
- Weld.Parent = Ball
- CameraAngleUpdateConnection = RS.Heartbeat:Connect(UpdateCameraAngle)
- Humanoid = hum
- Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
- wait()
- local animator = Humanoid
- for _,anim in pairs(animator:GetPlayingAnimationTracks()) do
- anim:Stop(0.1)
- end
- AnimPlayedConnection = animator.AnimationPlayed:Connect(AnimationPlayed)
- end
- Tool.Equipped:Connect(EquipTool)
- Tool.Unequipped:Connect(UnequipTool)
- ]],owner.PlayerGui)
- local ptr = Instance.new("ObjectValue")
- ptr.Name = "ToolPointer"
- ptr.Value = Tool
- ptr.Parent = ls
- local Ball = Instance.new("Part")
- Ball.Material = Enum.Material.SmoothPlastic
- Ball.Transparency = 0.75
- Ball.Shape = Enum.PartType.Ball
- Ball.Size = Vector3.new(8,8,8)
- Ball.Name = "Ball"
- Ball.Parent = Tool
- local Players = game:GetService("Players")
- Tool.Equipped:Connect(function()
- local Character = Tool.Parent
- local Player = Players:GetPlayerFromCharacter(Character)
- if not Player then return end
- Ball:SetNetworkOwner(Player)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement