Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Movement and rotation troubles in VR?

Asked by 3 years ago

So I have been making my first VR game and I want to be able to move in game

I have the grab script hands head etc but I just cant work out how to move using the thumbpad(htc vive) or the trigger on the controller in the direction your facing

I also need a rotation script

Here are my scripts

  • local script
wait(4)

workspace.ThingsHappen.MoveMe:FireServer()

workspace.CurrentCamera.CameraType = "Scriptable"
wait()
workspace.CurrentCamera.CFrame = CFrame.new()

local VRService = game:GetService("VRService")
local InputService = game:GetService("UserInputService")

VRService.UserCFrameChanged:Connect(function()
    local LeftHand = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
    local RightHand = VRService:GetUserCFrame(Enum.UserCFrame.RightHand)
    local Head = VRService:GetUserCFrame(Enum.UserCFrame.Head)
    workspace.ThingsHappen.STUFF2Happen:FireServer(RightHand,LeftHand,Head)
end)

InputService.InputBegan:Connect(function(Type, Stuff)
    if Type.KeyCode == Enum.KeyCode.ButtonR1 then
        workspace.ThingsHappen.RightGrip:FireServer()
    elseif Type.KeyCode == Enum.KeyCode.ButtonL1 then
        workspace.ThingsHappen.LeftGrip:FireServer()
    end
end)

InputService.InputEnded:Connect(function(Type, Stuff)
    if Type.KeyCode == Enum.KeyCode.ButtonR1 then
        workspace.ThingsHappen.RightGo:FireServer()
    elseif Type.KeyCode == Enum.KeyCode.ButtonL1 then
        workspace.ThingsHappen.LeftGo:FireServer()
    end
end)

server script

function ItsHim(player, RightHand, LeftHand, Head)
    workspace.Johna.CFrame = (RightHand)
    workspace.Jenna.CFrame = (LeftHand)
end

function GripGoRight()
    if workspace:FindFirstChild("GrippedRight") ~= nil then
        workspace.GrippedRight.AlignOrientation.Attachment1 = nil
        workspace.GrippedRight.AlignPosition.Attachment1 = nil
        workspace.GrippedRight.Parent = workspace.ThingsInHere
    end
end

function GripGrabRight()
    local TheKids = workspace.ThingsInHere:GetChildren()
    local DistanceRight = 1
    for i = 1,#TheKids do
        if (TheKids[i].Attachment.WorldPosition - workspace.Johna.Position).magnitude<DistanceRight and TheKids[i].AlignOrientation.Attachment1 == nil then
            GripGoRight()
            DistanceRight = (TheKids[i].Attachment.WorldPosition - workspace.Johna.Position).magnitude
            TheKids[i].AlignOrientation.Attachment1 = workspace.Johna.Attachment
            TheKids[i].AlignPosition.Attachment1 = workspace.Johna.Attachment
            TheKids[i].Name = "GrippedRight"
            TheKids[i].Parent = workspace
        end
    end
end

function GripGoLeft()
    if workspace:FindFirstChild("GrippedLeft") ~= nil then
        workspace.GrippedLeft.AlignOrientation.Attachment1 = nil
        workspace.GrippedLeft.AlignPosition.Attachment1 = nil
        workspace.GrippedLeft.Parent = workspace.ThingsInHere
    end
end

function GripGrabLeft()
    local TheKids = workspace.ThingsInHere:GetChildren()
    local DistanceLeft = 1
    for i = 1,#TheKids do
        if (TheKids[i].Attachment.WorldPosition - workspace.Jenna.Position).magnitude<DistanceLeft and TheKids[i].AlignOrientation.Attachment1 == nil then
            GripGoLeft()
            DistanceLeft = (TheKids[i].Attachment.WorldPosition - workspace.Jenna.Position).magnitude
            TheKids[i].AlignOrientation.Attachment1 = workspace.Jenna.Attachment
            TheKids[i].AlignPosition.Attachment1 = workspace.Jenna.Attachment
            TheKids[i].Name = "GrippedLeft"
            TheKids[i].Parent = workspace
        end
    end
end

function MoveThem(player)
    player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0,1000,0))
    player.Character.HumanoidRootPart.Anchored = true
end

script.STUFF2Happen.OnServerEvent:Connect(ItsHim)
script.RightGrip.OnServerEvent:Connect(GripGrabRight)
script.RightGo.OnServerEvent:Connect(GripGoRight)
script.LeftGrip.OnServerEvent:Connect(GripGrabLeft)
script.LeftGo.OnServerEvent:Connect(GripGoLeft)

script.MoveMe.OnServerEvent:Connect(MoveThem)

1 answer

Log in to vote
0
Answered by 3 years ago

This might help you, if you go to roblox studio and open up the VR game you have and go to view-->ObjectBrowser and then scroll all the way down and click on VRTouchpadMode. There are commands that you can write in your script and one of the commands are VirtualThumbstick. I think it is a bool value I maybe wrong, but you would set that to equal true.

Below is a picture of what I am telling you

https://ibb.co/tq1Ny9P

Ad

Answer this question