So basically if you walk into a part, your character will keep turning right. I talked to AllYourBlox about this and he said it was probably because there was a feedback loop (i.e My Character was setting my Camera’s orientation, then my camera was setting my character’s orientation).
Right now I feel like I’m hitting my head against a wall to fix this lol, I thought I’d post my code here and see if you guys could help!
If I’ve neglected some important code form below, please let me know!
I’ll leave a link at the bottom so you can see it in action
function GetPopperPosition(Head, NextCamPosition)
local ray = Ray.new(Head.CFrame.p, (NextCamPosition - Head.CFrame.p).unit * 100)
local _, HitPosition = workspace:FindPartOnRayWithIgnoreList(ray, CharacterStatus.IgnoreList)
return Head.Position:lerp(HitPosition, .8)
end
function AdjustForMouseDelta()
local X = 0
if MouseDelta then
X = MouseDelta.X/150
if Y-MouseDelta.Y/150 < 1 and MouseDelta.Y < 0 then
Y = Y-MouseDelta.Y/150
elseif Y-MouseDelta.Y/150 > -1 and MouseDelta.Y > 0 then
Y = Y-MouseDelta.Y/150
end
Y = math.clamp(Y, -1, 1)
MouseDelta = nil
end
return X
end
RenderStepped = function(Character, Humanoid)
if (not Character:FindFirstChild("Head")) or (not Character:FindFirstChild("HumanoidRootPart")) then
return
end
local HRP = Character.HumanoidRootPart
local X = AdjustForMouseDelta()
HRP.CFrame = HRP.CFrame * CFrame.fromEulerAnglesXYZ(0,-X,0)
local PositionBehindSubject = (HRP.CFrame * CFrame.fromEulerAnglesXYZ(Y,0,0) * CFrame.new(0, 0, CurrentZOffset) ).p
local TargetPosition = Vector3.new(PositionBehindSubject.X, PositionBehindSubject.Y, PositionBehindSubject.Z)
local CurrentXOffset = Lerp(1, OTSXOffset, CurrentZOffset / OTSZOffset)
local TargetCFrame = CFrame.new(TargetPosition, HRP.CFrame.p) * CFrame.new(CurrentXOffset, 3, 0)
TargetCFrame = Camera.CFrame:lerp(TargetCFrame, .5)
local PopperPosition = GetPopperPosition(Character.Head, TargetCFrame.p)
if (HRP.CFrame.p - TargetPosition).magnitude > (HRP.CFrame.p - PopperPosition).magnitude then
TargetCFrame = CFrame.new(PopperPosition, PopperPosition + TargetCFrame.lookVector)
end
Camera.CFrame = TargetCFrame
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end;
Press C to turn it on