Players camera position not updating

I am adding the ability to slide into my game. I am trying to move the players camera position to be lower to the ground when sliding but I cant get it to work. I’m trying to get it to just go to the position of the head so I can use Vector 3 to adjust it from there.

I did use CFrame and it worked but it snaps to the rotation as well

UserInputServ.InputBegan:Connect(function(input, gameProcessed)
	
	if input.KeyCode == Enum.KeyCode.C then
		
		Slide1stHalfAnim:Play()
		Slide1stHalfAnim.Stopped:Wait()
		Slide2stHalfAnim:Play()
		Slide2stHalfAnim.Looped = true
		TS:Create(workspace.CurrentCamera, TweenInfo.new(.1, Enum.EasingStyle.Quad), {FieldOfView = workspace.CurrentCamera.FieldOfView + 5}):Play()
		camera.CFrame.Position = player.Character:WaitForChild("Head").CFrame.Position
		
	end
	
end)
1 Like

I am not sure where is your script located, but doing the following, it seems that it is just an error with the little meaning of the Camera’s CFrame (as well as locating the player without a parameter).

UserInputServ.InputBegan:Connect(function(input, gameProcessed, player)
	
	if input.KeyCode == Enum.KeyCode.C then
		
		Slide1stHalfAnim:Play()
		Slide1stHalfAnim.Stopped:Wait()
		Slide2stHalfAnim:Play()
		Slide2stHalfAnim.Looped = true
		TS:Create(workspace.CurrentCamera, TweenInfo.new(.1, Enum.EasingStyle.Quad), {FieldOfView = workspace.CurrentCamera.FieldOfView + 5}):Play()
		camera.CFrame = player.Character:WaitForChild("Head").CFrame
		
	end
	
end)
1 Like

Hello :wave:

You can’t set the Position of a CFrame the way you did, you need to create a new CFrame with the desidered position.
Example:

local desidered_cframe = CFrame.new(player.Character:WaitForChild("Head").Position)
camera.CFrame = desidered_cframe

Creating a new CFrame only setting the position will always result on cframes with the exact same orientation,

If you want to keep the camera’s CFrame orientation, you can just set the LookVector of the desidered_cframe as the camera.CFrame.LookVector:

local desidered_cframe = CFrame.new(
    player.Character:WaitForChild("Head").Position, -- position
    camera.CFrame.LookVector -- LookVector
)
camera.CFrame = desidered_cframe

also, remember that you need to set the camera’s CameraType to Scriptable (Enum.CameraType.Scriptable) before doing any change on camera with scripting.

If you have any questions, feel free to ask, and sorry if I didn’t helped you.

2 Likes
local desired_pos = player.Character:WaitForChild("Head").Position
camera.CFrame = camera.CFrame - camera.CFrame.Position + desired_pos
2 Likes


CFrames | Roblox Creator Documentation

Yeah, I already tested, and it really works
it’s a nice way, and short as well.

No your a big help! sorry I didn’t reply sooner but I made the post and went to bed. Thank you for breaking down everything so I actually understand it fully. I hope you have a great day or night :slight_smile: !

1 Like

I am still having a bug though where the players camera stays in the same position and it just snaps to a certain rotation. I am using a module that you can do camera shake and stuff with and it might be causing issues. I might have to make an object and just set the camera to that objects position.

1 Like

hm, if a module might be causing issues, how would that solve it?
perhaps you could just disable the camera shake while your script is doing its changes on the camera, not sure.

Yeah fair point on that one. And your right it didn’t solve it. I was just toying with adding sliding to my game so for now I’m going to scrap the mechanic then come back to it when I’m more experienced and if I actually want it in my game.

Thanks for all the help! I still have definitely learned some valuable things here :slight_smile:
I hope you all have a good day and or night!

1 Like