I'm working on this game which changes the player's camera here and there and even puts them in first person. My problem here is that after the player is in first person, their character starts to move in a weird way, almost as if they were viewing themselves from a camera cframed to a part. Does anyone know how I can fix this? Thank you!
Player's camera top view: https://i.gyazo.com/340727e0e8ea52369848252b65b14acf.gif
Player's camera first person: https://i.gyazo.com/8320be3ae548065eec533f96fffdf2ef.gif
Players' camera back to top view with issue: https://i.gyazo.com/c0c5f7ef790680c0dae380aeb3eef517.gif
Code:
-------------------------------------------------------------------------Locals
local RunSer = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Cam = workspace.CurrentCamera
local RootP = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local Mode = script.Parent.Mode
local Cam_Height = script.Parent.Cam_Height --Just some camera values, they're not connected to the issue
local Cam_Rotation = script.Parent.Cam_Rotation
local Cam_FarX = script.Parent.Cam_FarX
local Cam_FarZ = script.Parent.Cam_FarZ
local Cam_RotationZ = script.Parent.Cam_RotationZ
local Cam_RotationY = script.Parent.Cam_RotationY
-------------------------------------------------------------------------Default
Cam.CameraType =Enum.CameraType.Scriptable
-------------------------------------------------------------------------RunServ
RunSer.RenderStepped:Connect(function()
if Mode.Value == "Top" then
Cam.CameraType = Enum.CameraType.Scriptable
Cam.CameraSubject = Character
game:GetService("TweenService"):Create(Cam,TweenInfo.new(.2,Enum.EasingStyle.Linear),{CFrame = CFrame.new(RootP.Position) * CFrame.fromEulerAnglesXYZ(-Cam_Rotation.Value,Cam_RotationY.Value,Cam_RotationZ.Value)+ Vector3.new(Cam_FarX.Value,Cam_Height.Value,Cam_FarZ.Value)}):Play()
elseif Mode.Value == "FirstP" then
local CT = tick() --All this is just for the view bobbing effect
Cam.CameraType = Enum.CameraType.Custom
Player.CameraMode = Enum.CameraMode.LockFirstPerson
if Humanoid.MoveDirection.Magnitude > 0 then
local X = math.cos(CT * 10) * .25
local Y = math.abs(math.sin(CT * 10)) * .25
Humanoid.CameraOffset = Humanoid.CameraOffset:lerp(Vector3.new(X,Y,0), .25)
else
Humanoid.CameraOffset = Humanoid.CameraOffset * .75
end
elseif Mode.Value == "None" then --This isn't connected to the issue either
end
end)
