Problem with Camera

I am making an RPG game that has a camera that is above the character to a certain degree. Here’s what it looks like:
https://gyazo.com/bca005a19e5e97a528d6f23fcc3ee529

Now the camera itself is doing pretty epic. I also made a script that triggers whenever the player goes inside a house (making the roof transparent so you can explore it without difficulty). Here’s what it looks like:
https://gyazo.com/b374f60c752d5df9d1d245889694c048

As you can see, the camera zooms in a bit when I enter the house as well. My problem is that sometimes if I stand by the door, the camera starts zooming in weird locations. (I am using the touch event to determine whether the user is in the house or not. The transparency seems to be working fine and it isnt breaking but the camera is a big issue. I used raycasting as well. Here’s what I tried:

wait(1)

while wait(0.5) do
    local MyRayCast = Ray.new(game.Players.LocalPlayer.Character.HumanoidRootPart.Position, game.Players.LocalPlayer.Character.HumanoidRootPart.Position - Vector3.new(0,3,0))
	local part = workspace:FindPartOnRay(MyRayCast)
	if part then
		if part.Name == 'Floor' then
			repeat
				wait()
				_G.CAMERA_OFFSET = _G.CAMERA_OFFSET - Vector3.new(0,1,0)
			until _G.CAMERA_OFFSET == Vector3.new(-1,20,10)
		else
			repeat
				wait()
				_G.CAMERA_OFFSET = _G.CAMERA_OFFSET + Vector3.new(0,1,0)
			until _G.CAMERA_OFFSET == Vector3.new(-1,25,10)
		end
	end
end

But that didn’t seem to work because it never got to the value. Tried while loops as well (didn’t do too well).
Any help is appreciated.

Here’s more information (it might help find the problem. not too sure):

This is what the issue actually looks like (It happens pretty regularly):
https://gyazo.com/3ace7ba4d19e2928ad29df1a797f9ac7

Heres my touched event script:

door.Touched:Connect(function(player)
	if player.Parent:FindFirstChild("Humanoid") then
		if inside and debounce then
			debounce = false
			unzoom:FireClient(game.Players:GetPlayerFromCharacter(player.Parent))
			for i,v in pairs(house:GetChildren()) do
				if v.Name == "Wall" then
					v.Transparency = 0
				end	
				if v.Name == "Wedge" then
					v.Transparency = 0
				end
			end
			wait(0)
			debounce = true
		elseif inside == false and debounce then
			debounce = false
			zoom:FireClient(game.Players:GetPlayerFromCharacter(player.Parent))
			for i,v in pairs(house:GetChildren()) do
				if v.Name == "Wall" then
					v.Transparency = 0.2
				end	
				if v.Name == "Wedge" then
					v.Transparency = 0.8
				end
			end
			wait(0)
			debounce = true
		end
	end

end)

Have you checked whether Player.DevCameraOcclusionMode is set to Zoom or Invisicam?

Also, if you’re controlling the camera manually, you might want to set the CameraType to Scriptable

(Haven’t checked your code as I’m in a rush).

Hey, the camera is scriptable. The camera seems to be doing fine. My main problem is getting the zoom function to work.
Here is what I have:

A house that has a detection part at the door way. Once it detects someone it fires a remote that zooms in the client’s camera. The zooming in part is where it gets messed up.

I don’t see a declaration for “inside”.
Perhaps you could create an instance in your character, like an IntValue, call it “Inside”, and then search for that in your function before calling your zoom method.

Remove when you leave the house.

Or just cast a ray from your character’s head to the camera to see if your character is obstructed by an object.

You can run this all on the client then and remove a burden on the server.

1 Like

Hey thanks for the help. I already declared the inside variable (didn’t post the full script). Here was my final solution though:

-- Server to Client Eventts

zoom.OnClientEvent:Connect(function()
	
	repeat
		local target = string.split(tostring(_G.CAMERA_OFFSET))
		wait()
		_G.CAMERA_OFFSET = _G.CAMERA_OFFSET - Vector3.new(0,0.2,0)
	until tonumber(target[2]) <= 20
end)

unzoom.OnClientEvent:Connect(function()
	repeat
		local target = string.split(tostring(_G.CAMERA_OFFSET))
		wait()
		_G.CAMERA_OFFSET = _G.CAMERA_OFFSET + Vector3.new(0,0.2,0)
	until tonumber(target[2]) >= 25
end)

It seems to be working so I think I did it haha.

1 Like