Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This is a rewritten version of the original GodVR script that I wrote
- Everything is subject to change
- The0neThe0nly
- TODO:
- + Add two "hitboxes"
- + Find a better way to scale hats/head mesh
- - Add more tools
- + CFrame touched event fix
- + Chat bubbles
- Tool Entry Format:
- {{name, BrickColor, init func, exit func, contact func, trigger func}, {name, BrickColor, property func, contact func, trigger func}, ...}
- - Each function's first argument must be a table for the hand being used
- - Contact function takes part object as second argument
- - Trigger function takes input object as second argument
- Arm Format:
- {{handObj, handSurface, handText, handLight}, toolState, Enum.UserCFrame.Hand, triggered}
- --]]
- local function empty() end
- local camera = workspace.CurrentCamera
- local scale = 1
- local left = {{nil, nil, nil, nil}, 1, Enum.UserCFrame.LeftHand, false}
- local right = {{nil, nil, nil, nil}, 1, Enum.UserCFrame.RightHand, false}
- local headMarker, hats, basecframe
- local tools = {{"Default", BrickColor.new("White"), empty, empty, empty, empty},
- {"Collide", BrickColor.new("White"), (function(hand) hand[1][1].Transparency = 0 hand[1][1].CanCollide = true end), (function(hand) hand[1][1].Transparency = 0.5 hand[1][1].CanCollide = false end), empty, empty},
- {"Grab", BrickColor.new("Really black"), empty, empty, (function(hand, part)
- local x = Instance.new("BodyPosition", camera)
- x.MaxForce = Vector3.new(100000, 100000, 100000)
- while hand[4] and (part.Parent:FindFirstChild("Torso") ~= nil or not part.Anchored) do
- wait()
- if part.Parent:FindFirstChild("Torso") ~= nil then
- x.Parent = part.Parent.Torso
- x.Position = hand[1][1].CFrame.p
- elseif not part.Anchored then
- x.Parent = part
- x.Position = hand[1][1].CFrame.p
- end
- end
- x:Destroy()
- end), empty},
- {"Kill", BrickColor.new("Really red"), empty, empty, (function(hand, part)
- if part.Parent:FindFirstChild("Humanoid") ~= nil then
- if part.Parent:FindFirstChild("ForceField") ~= nil then
- part.Parent["ForceField"]:Destroy()
- end
- part.Parent:BreakJoints()
- end
- end), empty},
- {"Vicinity Explode", BrickColor.new("Deep orange"), empty, empty, (function(hand, part)
- if part.Parent:FindFirstChild("Torso") ~= nil or not part.Anchored then
- local x = Instance.new("Explosion", workspace)
- if part.Parent:FindFirstChild("Torso") ~= nil then
- x.Position = part.Parent.Torso.Position
- elseif not part.Anchored then
- x.Position = part.Position
- end
- end
- end), empty},
- {"Explode", BrickColor.new("Deep orange"), (function(hand) local x = Instance.new("Fire", hand[1][1]) x.Heat = 3 x.Size = scale end), (function(hand) hand[1][1].Fire:Destroy() end), empty, (function(hand, input)
- while input.Position.z == 1 do
- wait()
- local x = Instance.new("Explosion", workspace)
- x.Position = Vector3.new(hand[1][1].CFrame.x-(0.4*scale), hand[1][1].CFrame.y, hand[1][1].CFrame.z)
- end
- end)},
- {"Trip", BrickColor.new("New Yeller"), empty, empty, (function(hand, part)
- if part.Parent:FindFirstChild("Humanoid") ~= nil and not part.Parent.Humanoid.PlatformStand then
- part.Parent.Humanoid.PlatformStand = true -- this is not a good way to trip people
- wait(1)
- part.Parent.Humanoid.PlatformStand = false
- end
- end), empty},
- {"Scale", BrickColor.new("Parsley green"), empty, empty, empty, (function(hand, input)
- local newscale = 0
- local ypos = hand[1][1].CFrame.y
- while input.Position.z == 1 do
- wait()
- newscale = ((hand[1][1].CFrame.y-ypos)/scale)*10
- hand[1][3].Text = "Scale: "..tostring(scale)
- if newscale >= 0 then
- if scale < 1 then
- newscale = math.ceil(hand[1][1].CFrame.y-ypos)/10
- if (newscale+scale) > 1 then
- newscale = 1 - scale
- end
- else
- newscale = math.ceil(newscale)
- end
- hand[1][3].Text = hand[1][3].Text.."\n+"..tostring(newscale)
- else
- if scale <= 1 then
- newscale = math.floor(hand[1][1].CFrame.y-ypos)/10
- else
- newscale = math.floor(newscale)
- end
- hand[1][3].Text = hand[1][3].Text.."\n-"..tostring(math.abs(newscale))
- end
- end
- scale = scale + newscale
- if scale < 0.3 then
- scale = 0.3
- end
- right[1][1].Size = Vector3.new(0.4, 0.4, 1)*scale
- left[1][1].Size = Vector3.new(0.4, 0.4, 1)*scale
- headMarker.Mesh.Scale = Vector3.new(1, 1, 1)*scale
- for i=1,#hats do
- wait()
- hats[i].Mesh.Scale = Vector3.new(1, 1, 1)*scale
- end
- camera.CoordinateFrame = CFrame.new(camera:GetRenderCFrame().x, camera:GetRenderCFrame().y+(newscale), camera:GetRenderCFrame().z)
- camera.HeadScale = scale
- hand[1][3].Text = "Scale: "..tostring(scale)
- end)}
- }
- local InputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local character = workspace:WaitForChild(game.Players.LocalPlayer.Name)
- local VRService = game:GetService("VRService")
- local function switch(hand) -- no need for input arg
- tools[hand[2]][4](hand) -- exit
- if hand[2] ~= #tools then
- hand[2] = hand[2] + 1
- else
- hand[2] = 1
- end
- hand[1][3].Text = tools[hand[2]][1]
- hand[1][1].BrickColor = tools[hand[2]][2]
- hand[1][4].Color = tools[hand[2]][2].Color
- tools[hand[2]][3](hand) -- init
- end
- local function gripped(hand, input)
- while input.Position.z == 1 do
- wait()
- local controllerCFrame = camera.CoordinateFrame*VRService:GetUserCFrame(hand[3])
- local positionChange = (controllerCFrame * CFrame.new(0*scale, 0*scale, (-0.1*scale)-1)).p - controllerCFrame.p
- --camera.CoordinateFrame = CFrame.new(positionChange.x, 0, positionChange.z) * camera.CoordinateFrame
- camera.CoordinateFrame = CFrame.new(positionChange.x, positionChange.y, positionChange.z) * camera.CoordinateFrame
- end
- end
- local function triggered(hand, input) -- lol
- tools[hand[2]][6](hand, input)
- while input.Position.z == 1 do
- wait()
- hand[4] = true
- end
- hand[4] = false
- end
- wait(1) -- hack
- if VRService.VREnabled and not workspace.FilteringEnabled then
- VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch) -- WIP hotfix
- VRService:SetTouchpadMode(Enum.VRTouchpad.Right, Enum.VRTouchpadMode.Touch)
- pcall(function() game.Players.LocalPlayer.TeamColor = game.Teams.Gods.TeamColor end) -- if in my test game
- camera.CameraType = Enum.CameraType.Scriptable
- basecframe = character.Head.CFrame
- camera.CoordinateFrame = CFrame.new(basecframe.x, basecframe.y+(scale-1), basecframe.z) -- this is a terrible way to do this
- camera.HeadScale = scale
- InputService.MouseIconEnabled = false
- --game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Chat, false)
- game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
- game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
- local colors = character:WaitForChild("Body Colors"):clone()
- hats = {}
- for i,v in pairs(character:GetChildren()) do
- wait()
- if v:IsA("Accoutrement") then
- table.insert(hats, v.Handle:clone())
- end
- end
- headMarker = character.Head:clone()
- for i,v in pairs(headMarker:GetChildren()) do
- wait()
- if v:IsA("Sound") or v:IsA("Weld") then
- v:Destroy()
- end
- end
- character:ClearAllChildren()
- colors.Parent = character
- headMarker.Anchored = true
- headMarker.LocalTransparencyModifier = 1
- headMarker.Mesh.Scale = Vector3.new(1, 1, 1) * scale
- headMarker.Parent = character
- for i=1,#hats do
- wait()
- hats[i].Anchored = true
- hats[i].LocalTransparencyModifier = 1
- hats[i].Mesh.Scale = hats[i].Mesh.Scale * scale
- hats[i].Parent = headMarker
- end
- headMarker.CanCollide = false
- local hand1Marker = Instance.new("Part", character)
- hand1Marker.Name = "RightHand"
- hand1Marker.BrickColor = tools[1][2]
- hand1Marker.Transparency = 0.5
- hand1Marker.Anchored = true
- hand1Marker.CanCollide = false
- hand1Marker.Locked = true
- hand1Marker.TopSurface = "Smooth"
- hand1Marker.BottomSurface = "Smooth"
- hand1Marker.Size = Vector3.new(0.4, 0.4, 1)*scale
- right[1][1] = hand1Marker
- local hand2Marker = right[1][1]:clone()
- hand2Marker.Name = "LeftHand"
- hand2Marker.Parent = character
- left[1][1] = hand2Marker
- local surfaceR = Instance.new("SurfaceGui", camera)
- surfaceR.Adornee = right[1][1]
- surfaceR.Face = "Top"
- right[1][2] = surfaceR
- local surfaceL = right[1][2]:clone()
- surfaceL.Parent = camera
- surfaceL.Adornee = left[1][1]
- left[1][2] = surfaceL
- local txtR = Instance.new("TextLabel", right[1][2])
- txtR.BackgroundTransparency = 1
- txtR.Rotation = 180
- txtR.Size = UDim2.new(1, 0, 1, 0)
- txtR.Font = "ArialBold"
- txtR.FontSize = "Size96"
- txtR.Text = tools[1][1]
- txtR.TextColor3 = Color3.new(1, 1, 1)
- txtR.TextStrokeTransparency = 0.5
- right[1][3] = txtR
- local txtL = right[1][3]:clone()
- txtL.Parent = left[1][2]
- left[1][3] = txtL
- local plR = Instance.new("PointLight", right[1][1])
- plR.Brightness = math.huge
- plR.Range = scale + 6
- plR.Shadows = true
- right[1][4] = plR
- local plL = right[1][4]:clone()
- plL.Parent = left[1][1]
- left[1][4] = plL
- right[1][1].Touched:connect(function(part) tools[right[2]][5](right, part) end)
- left[1][1].Touched:connect(function(part) tools[left[2]][5](left, part) end)
- RunService.Heartbeat:connect(function() -- 60 hz...?
- local HeadCFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
- local RightHandCFrame = VRService:GetUserCFrame(right[3])
- local LeftHandCFrame = VRService:GetUserCFrame(left[3])
- local scaledLeftHandCFrame = CFrame.new(LeftHandCFrame.p*(scale-1))*LeftHandCFrame
- local scaledRightHandCFrame = CFrame.new(RightHandCFrame.p*(scale-1))*RightHandCFrame
- local mainCFrame1 = camera.CoordinateFrame * scaledRightHandCFrame
- local mainCFrame2 = camera.CoordinateFrame * scaledLeftHandCFrame
- right[1][1].CFrame = mainCFrame1
- left[1][1].CFrame = mainCFrame2
- headMarker.CFrame = camera:GetRenderCFrame()
- for i=1,#hats do
- hats[i].CFrame = camera:GetRenderCFrame()
- hats[i].CFrame = camera:GetRenderCFrame()
- end
- end)
- local function handleInput(input) -- no gameProcessed for now
- if input.UserInputState == Enum.UserInputState.Begin then
- print(input.KeyCode)
- if input.KeyCode == Enum.KeyCode.ButtonR3 then -- Right Touchpad
- switch(right)
- elseif input.KeyCode == Enum.KeyCode.ButtonL3 then -- Left Touchpad
- switch(left)
- elseif input.KeyCode == Enum.KeyCode.ButtonR2 then -- Right Trigger
- triggered(right, input)
- elseif input.KeyCode == Enum.KeyCode.ButtonL2 then -- Left Trigger
- triggered(left, input)
- elseif input.KeyCode == Enum.KeyCode.ButtonR1 then -- Right Grip
- gripped(right, input)
- elseif input.KeyCode == Enum.KeyCode.ButtonL1 then -- Left Grip
- gripped(left, input)
- end
- elseif input.UserInputState == Enum.UserInputState.End then
- -- nothing for now
- elseif input.UserInputState == Enum.UserInputState.Change then
- -- nothing for now
- end
- end
- InputService.InputBegan:connect(handleInput)
- InputService.InputEnded:connect(handleInput)
- InputService.InputChanged:connect(handleInput)
- elseif not VRService.VREnabled then
- error("\nYou don't have a VR headset plugged in or one was not detected\nVRService.VREnabled: "..tostring(VRService.VREnabled))
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement