Hey there! So basically I want the players character Torso to move to where the player is facing. With this I would like it to be able to do a clamp thing. What I mean by this is if you turn so much to the left/right then your torso moves. If you can help me with this it would be great. You dont need to know anything about VR since its just CFrame.
Interesting concept. The biggest issue here is that humanoids do not like their torso being tilted to much up and down and it causes very strange behaviour.
So you need to be carful to apply only yaw, while ignoring (or heavily reducing) roll and pitch.
I just realized while writing this, that you are probably not using a humanoid in the first place.
Also you mentioned you would like the torso to do “clamp thing” aka hysteresis.
Let’s see.
Do you already have camera render? You can get it this way. I suggest to always use this instead of head rotation. Use the source material whenever possible.
local camRender = workspace.Camera:GetRenderCFrame()
I am assuming you are not using humanoids. This solution will only work for non-humanoid objects.
We are only interested in yaw rotation, and not in roll or pitch.
For stiff movement you will have something like this. This script will probably mess up your movement script as it will overwrite torso position. You will need to combine it with your current movement script:
For “clamp thing” you will probably need to do some extra checks. I would probably use Orientation Lets assume maximum leeway is about 45 degree:
local x,y,z = camRender:ToOrienation
local diff = math.abs(vrCharacter["Torso"].Orientation.Y - math.deg(y))
if diff > 45 and diff < 315 then
CFrame.new(vrCharacter["Torso"].Position,Vector3.new(camRender.LookVector.X,0,camRender.LookVector.Z)
end
local camRender = camera:GetRenderCFrame()
local x,y,z = camRender:ToOrientation()
local diff = math.abs(vrCharacter["Torso"].Orientation.Y - math.deg(y))
if (diff > 45 and diff < 315) then
vrCharacter["Torso"].CFrame = CFrame.new(vrCharacter["Torso"].Position, Vector3.new(camRender.LookVector.X, 0, camRender.LookVector.Z))
end
Yeah sorry my bad. Not my best day.
Here is the fixed version (I have tested it this time):
--prep
local torso = vrCharacter["Torso"]
--inside RenderStepped
local camRender = cam:GetRenderCFrame()
local x,y,z = camRender:ToOrientation()
local diff = torso.Orientation.Y - math.deg(y)
if diff > 45 and diff < 315 then
torso.CFrame = CFrame.new(torso.Position) * CFrame.Angles(0,y,0)
elseif diff < -45 and diff > -315 then
torso.CFrame = CFrame.new(torso.Position) * CFrame.Angles(0,y,0)
end