So I’ve been messing around with VR scripts again, and I’ve come across this really annoying issue with the camera.
I have a custom camera script that rotates the camera left and right depending on the thumbstick, and it only moves in the relative direction the theta is facing, but doesn’t account for where the camera lookvector is.
Video of the phenomenon happening:
Here’s my camera script incase it has anything to do with this:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local VRService = game:GetService("VRService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Bindables = ReplicatedStorage:WaitForChild("Bindables")
local UpdateHands = Bindables:WaitForChild("UpdateHands")
local USettings = UserSettings()
local UserGameSettings = USettings.GameSettings
local CurrentCamera = workspace.CurrentCamera
local Scriptable = Enum.CameraType.Scriptable
local Thumbstick = Enum.KeyCode.Thumbstick2
local Camera = Enum.RenderPriority.Camera
local UserHead = Enum.UserCFrame.Head
local CFAng = CFrame.Angles
local CFNew = CFrame.new
local V3New = Vector3.new
local rad = math.rad
local Turning, Theta = 0, 0
UserInputService.InputChanged:Connect(function(Input)
if Input.KeyCode == Thumbstick then
Turning = Input.Position.X
end
end)
RunService:BindToRenderStep("CameraMovement", Camera.Value + 1, function(dT)
if Turning > .25 or Turning < -.25 then
local Scale = dT * 60
Theta = Theta - ((Turning * (UserGameSettings.MouseSensitivity * 3)) * Scale)
end
local Character = Player.Character
local RootPart = Character and (Character.PrimaryPart or Character:FindFirstChild("HumanoidRootPart")) or nil
local Humanoid = Character and Character:FindFirstChild("Humanoid") or nil
if Humanoid and RootPart then
Humanoid.AutoRotate = false
local HeadCF = VRService:GetUserCFrame(UserHead)
local CamHeadCF = CurrentCamera.CFrame * HeadCF
local CamHeadLV = CamHeadCF.LookVector
local PosToUse = V3New(CamHeadLV.X, 0, CamHeadLV.Z)
CurrentCamera.CFrame = CFNew(RootPart.Position + V3New(0, Humanoid.HipHeight)) * CFAng(0, rad(Theta), 0)
RootPart.CFrame = CFNew(RootPart.Position, RootPart.Position + PosToUse)-- * CFAng(0, rad(Theta), 0)
end
UpdateHands:Fire()
end)
warn("CameraHandler.Init")
Any help is appreciated.