How do I stop my camera from going nuts when in first person?

i’m making a sliding mechanic, everything works really nice but the camera cframe change :angry: :-1:

in third person it works fine (minus the avatar wearables being visible)

but in first person it just spazzes out

to clarify, no, i do not want third person to be fixed, as the game will not support 3rd person

preview of what’s happening:

local plr = game:GetService("Players").LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local debounce = false
local connection = nil

local UIS = game:GetService("UserInputService")
local event = game:GetService("ReplicatedStorage"):WaitForChild("PlayerEvents").SlideEvent

local Anim = script:WaitForChild("SlideAnim")
local Camera = workspace:WaitForChild("Camera")

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.WalkSpeed > 16 then
			if debounce then return end
			debounce = true
			event:FireServer()
			local animator = Humanoid:FindFirstChildOfClass("Animator")
			if not animator then return end
			
			local Slide = animator:LoadAnimation(Anim)
			Slide:Play()
			
			connection = game:GetService("RunService").RenderStepped:Connect(function()
				Camera.CameraType = Enum.CameraType.Scriptable
				Camera.CFrame = Char.Head.CFrame
			end)
			
			Slide.Ended:Wait()
			connection:Disconnect()
			Camera.CameraType = Enum.CameraType.Custom
			
			task.wait(1)
			debounce = false
		end
	end
end)
4 Likes

bumping because i still haven’t fixed it :point_right: :point_left:

2 Likes

prob add a part on top if your character’s head that only moves in the z axis (a while loop should work), set your camera’s cframe to it, when the sliding anim ends destroy it and set ur cam back to normal

3 Likes

that didn’t do it :pensive: (character limit :interrobang: )

1 Like

have you done everything i provided?
send me the script.

1 Like

i’m gonna be honest i didn’t really use a while loop because i didn’t really know what you meant by it (:headstone:), but this is what i did:

if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.WalkSpeed > 16 then
			if debounce then return end
			debounce = true
			event:FireServer()
			local animator = Humanoid:FindFirstChildOfClass("Animator")
			if not animator then return end
			
			local Slide = animator:LoadAnimation(Anim)
			Slide:Play()
			
			local FOVIncrease = TS:Create(Camera, TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {FieldOfView = 110})
			local FOVDecrease = TS:Create(Camera, TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {FieldOfView = 90})
			
			
			FOVIncrease:Play()
			FOVIncrease.Completed:Wait()
			FOVDecrease:Play()
			
			local Part = Instance.new("Part")
			Part.Parent = Char.Head
			
			Part.Transparency = 1
			Part.CanCollide = false
			Part.Anchored = true
			
			
			connection = game:GetService("RunService").RenderStepped:Connect(function() -- i assume doing this is the error, but i wouldn't know
				Part.CFrame = Char.Head.CFrame
				Camera.CFrame = Part
			end)
			
			Slide.Ended:Wait()
			connection:Disconnect()
-- destroy here!!
			Camera.CameraType = Enum.CameraType.Custom
			
			task.wait(1)
			debounce = false
		end
1 Like

It might be because you’re changing CameraType every frame, try this

local plr = game:GetService("Players").LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local debounce = false
local connection = nil

local UIS = game:GetService("UserInputService")
local event = game:GetService("ReplicatedStorage"):WaitForChild("PlayerEvents").SlideEvent

local Anim = script:WaitForChild("SlideAnim")
local Camera = workspace:WaitForChild("Camera")

UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.WalkSpeed > 16 then
			if debounce then return end
			debounce = true
			event:FireServer()
			local animator = Humanoid:FindFirstChildOfClass("Animator")
			if not animator then return end
			
			local Slide = animator:LoadAnimation(Anim)
			Slide:Play()
			
            Camera.CameraType = Enum.CameraType.Scriptable

			connection = game:GetService("RunService").RenderStepped:Connect(function()
				Camera.CFrame = Char.Head.CFrame
			end)
			
			Slide.Ended:Wait()
			connection:Disconnect()
			Camera.CameraType = Enum.CameraType.Custom
			
			task.wait(1)
			debounce = false
		end
	end
end)

(This is an assumption and probably won’t work but I don’t see anything particularly wrong with your code)

2 Likes

that semi-fixed it, actually:

it still staggers, sadly

though i don’t necessarily expect myself to be using CameraType.Scriptable as i do want to allow the player to turn during the slide (unless there’s a way to code that in)

The staggering is caused by the camera returning to the old axis it was on while the CameraType was Custom, but I’m not sure how you can solve that

1 Like

i HATE the camera in ROBLOX :face_with_symbols_over_mouth:

i’m definitely gonna be stuck on this for a while

Instead of using RenderStepped, try using BindToRenderStep and change the priority.

The priority for camera is 200, so try a number under and above that.

1 Like

that kind of did something?

i mean setting the priority under 200 does this:

setting it above breaks the camera so i didn’t record a preview,

however note that the camera breaks after that (the bobbling actually makes the player walk sideways, and going into third person makes the camera follow the player’s head, though the third person issue isn’t really something i care about)

this is my first time using BindToRenderStep, so i’m not even sure if this code is correct:

game:GetService("RunService"):BindToRenderStep("moveCamera", 30, function()
				Camera.CFrame = Char.Head.CFrame
			end)
			
			Slide.Ended:Wait()
                        game:GetService("RunService"):UnBindFromRenderStep("moveCamera") -- i should probably store run service in a variable lol
			task.wait(1)
			debounce = false
local c = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local p = Instance.new("Part", c)
p.Name = "theGloriousPart"
p.Anchored = true
p.Transparency = 1
p.CanCollide = false

p.Position = c.Head.Position + Vector3.new(0,3,0)

local a = false

game.UserInputService.InputBegan:Connect(function(i)
	
	if i.KeyCode == Enum.KeyCode.E then
		
		workspace.CurrentCamera.CameraType = "Scriptable"
		
		a = false
		
		task.spawn(function()
			
			while task.wait() do
				workspace.CurrentCamera.CFrame = p.CFrame
				
				if a then
					break
				end
			end
			
		end)
		
		task.wait(2)
		
		a = true
		
		workspace.CurrentCamera.CameraType = "Custom"
		workspace.CurrentCamera.CFrame = c.Head.CFrame
	end
	
end)

while true do
	p.Position = c.Head.Position + Vector3.new(0,3,0)
	local c = workspace.CurrentCamera.CFrame -  workspace.CurrentCamera.CFrame.Position + p.Position;
	p.CFrame = c
	task.wait()
end

i’ve made a simple script that moves your camera’s cframe to the new part, change the task.wait(2) to task.wait(anim.Length)

2 Likes

truly the goat of camera scripting…

thanks!! :pray: :handshake: :heart:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.