Help with VR Teleport

Still Not Fixed

I am making a VR game and I decided that the game will use teleport locomotion.
The teleport on its own works fine but when I add it with the snap turning that I made I get a small offset from where I want to teleport to.
Here is the code that runs whenever I Teleport:

-- (TPSpot is the Position that i am teleporting to)
-- self.CameraCFrame is just the same as workspace.CurrentCamera.CFrame
-- self.UserCFrames is a table of all of the UserCFrames(Head, Floor and each Hand)
-- Headlock is on
self.CameraCFrame = CFrame.new(TPSpot-Vector3.new(0,self.UserCFrames.Floor.Y-self.UserCFrames.Head.Y,0)-self.UserCFrames.Head.Position)*self.CameraCFrame.Rotation

Here is the code that runs the snap turning:

self.CameraCFrame *= CFrame.Angles(0,math.rad(22.5*-InputPos.X),0)

Video of the issue (sorry abt the music lol):

If anyone could help me that would be great! (please…)
(if more info is needed please let me know)

3 Likes

A few days late to your request but i might be able to help you.
Based on your code i wrote a few lines myself. I’m not able to test it since i don’t own a VR Set.
Let me know if it does or doesn’t work! :+1:

local destinationPosition = TPSpot - Vector3.new(0, self.UserCFrames.Floor.Y - self.UserCFrames.Head.Y, 0) - self.UserCFrames.Head.Position -- Calculating the position

self.CameraCFrame = CFrame.new(destinationPosition) * self.CameraCFrame.Rotation -- This is used for Teleportation

self.CameraCFrame = self.CameraCFrame * CFrame.Angles(0, math.rad(22.5 * -InputPos.X), 0) -- This is used for snapping

1 Like

unfortunately this is just a neater version of the code in the original post and didnt solve the issue.
Thanks anyway.

It was worth a shot. I don’t think i’ll be able to help you more precisely since i do not own a vr set. Goodluck with your project though! :+1:

1 Like

thanks. i did attach a video of the issue incase that helps.

That surely helped. Could you try this?

local snapTurnAngle = math.rad(22.5 * -InputPos.X) -- Your snap angle value
local newRotation = self.CameraCFrame.Rotation * CFrame.Angles(0, snapTurnAngle, 0)
self.CameraCFrame = CFrame.new(self.CameraCFrame.Position, self.CameraCFrame.Position + (newRotation * self.CameraCFrame.LookVector))

This didnt work :confused:

The values might be a little off, But there is no more teleporting correct?

Unfortunately there is. I do know why this issue is occurring but i just dont know how to fix it. The reason it is teleporting when i turn is because of the offset between the cameraCFrame and the headCFrame making the head pivot around the cameraCFrame

Hmm okay, Well i have 2 more ideas. We can try subtracting or multiplying It should fix it hopefully :sweat_smile:

local snapTurnAngle = math.rad(45 * -InputPos.X)
local headPosition = self.UserCFrames.Head.Position
local newRotation = self.CameraCFrame.Rotation * CFrame.Angles(0, snapTurnAngle, 0)
self.CameraCFrame = CFrame.new(headPosition) * newRotation

Or this version

local snapTurnAngle = math.rad(22.5 * -InputPos.X)
local currentRotation = self.CameraCFrame - self.CameraCFrame.Position
local newRotation = CFrame.Angles(0, snapTurnAngle, 0)
self.CameraCFrame = CFrame.new(self.CameraCFrame.Position, self.CameraCFrame.Position + (newRotation * currentRotation))

the first script makes me go back to 0,0,0 whenever i turn and the second one somehow broke my teleport lol.
Video of the second one:

Haha okay, thats not meant to happen. I don’t know any big solutions then. I might try some code at home if i don’t forget to do so.

1 Like

bump. I still need this topic to be fixed so if anyone has worked with this type of stuff previously please reply.