I have made a basic VR Movement Script and I am wondering on how to rotate the camera, I have a value that changes on when I move my right controller’s stick but i am having problems on actually rotating the character. When I try to, the only thing that rotates is the head and the hands stay in its original place,
Here are the parts of the script related to it: (This is all in a single local script)
---Values---
local UIService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local VRService = game:GetService("VRService")
local PlayerService = game:GetService("Players")
local StarterGUI = game:GetService("StarterGui")
local plr = PlayerService.LocalPlayer
local VRCharacter
local cam = workspace.CurrentCamera
local HeadScale = 1
local UpdateEvent = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("VRUpdate")
local walkspeed = Vector3.new(50, 0 ,50)
local sprintM = .8
local walkM = .4
local Offset = 5
local currentRotation = 0
local LeftHand
local RightHand
local Head
local Torso
local locoBall
--Camrea and VR IRL Tracking--
local interval = .015
local lastServerTick = tick() + interval
RunService.RenderStepped:Connect(function(DT)
cam.HeadLocked = false
cam.CameraType = Enum.CameraType.Scriptable
cam.CameraSubject = VRCharacter.Head
local HeadCFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
cam.CFrame = CFrame.new(locoBall.Position.X, locoBall.Position.Y + Offset, locoBall.Position.Z) * CFrame.new(HeadCFrame.Position) * CFrame.Angles(HeadCFrame:ToEulerAnglesXYZ())
local RightHandCFrame = VRService:GetUserCFrame(Enum.UserCFrame.RightHand)
local LeftHandCFrame = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
local RightHandMathified = CFrame.new(cam.CFrame.Position) * CFrame.new((RightHandCFrame.p-HeadCFrame.Position)*HeadScale) * CFrame.fromEulerAnglesXYZ(RightHandCFrame:ToEulerAnglesXYZ())
local LeftHandMathified = CFrame.new(cam.CFrame.Position) * CFrame.new((LeftHandCFrame.p-HeadCFrame.Position)*HeadScale) * CFrame.fromEulerAnglesXYZ(LeftHandCFrame:ToEulerAnglesXYZ())
local HeadMathified = cam.CFrame
local TorsoMathified = CFrame.new(cam.CFrame.Position.X, cam.CFrame.Position.Y - 1.5, cam.CFrame.Position.Z) * CFrame.fromOrientation(0, math.rad(Head.Orientation.Y),0)
LeftHand.CFrame = LeftHandMathified
RightHand.CFrame = RightHandMathified
Head.CFrame = HeadMathified
Torso.CFrame = Torso.CFrame
if lastServerTick < tick() then
UpdateEvent:FireServer("CFrame", LeftHandMathified, RightHandMathified, HeadMathified, locoBall.CFrame, TorsoMathified)
lastServerTick = tick() + interval
print("Sent To Server")
end
end)
---Controls---
UIService.InputChanged:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Thumbstick1 then
if UIService:IsGamepadButtonDown(Enum.UserInputType.Gamepad1, Enum.KeyCode.ButtonL3) then
locoBall:FindFirstChild("BodyAngularVelocity").AngularVelocity = (((-cam:GetRenderCFrame().RightVector * input.Position.Y) + (cam:GetRenderCFrame().LookVector * input.Position.X)) * walkspeed * sprintM)
else
locoBall:FindFirstChild("BodyAngularVelocity").AngularVelocity = (((-cam:GetRenderCFrame().RightVector * input.Position.Y) + (cam:GetRenderCFrame().LookVector * input.Position.X)) * walkspeed * walkM)
end
elseif input.KeyCode == Enum.KeyCode.Thumbstick2 then
if input.Position.X >= .95 and turnDebounce == false then
print("ROTATE RIGHT")
turnDebounce = true
currentRotation += -45
task.wait(1)
turnDebounce = false
elseif input.Position.X <= -.95 and turnDebounce == false then
print("ROTATE LEFT")
turnDebounce = true
currentRotation += 45
task.wait(1)
turnDebounce = false
end
print(currentRotation)
end
end)
else
Any help would be appreciated!