Character rotation problem when trying to solve it's transparent parts during first person

so i have this problem, “sorry for bad quality”:

when camera scrolls in first person, the character appear transparent.

i did tried using camerasubject for it, but it wont apply with the player’s character rotation when in first person.
i did tried use runservice and loop through the character parts and set their transparency to 0 but still same issue.

local Run = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")

local mouse = game.Players.LocalPlayer:GetMouse()
local cam = workspace.CurrentCamera
local MaincamPart = workspace:WaitForChild("Map"):WaitForChild("camPart")

local playercharacter = game.Players.LocalPlayer.Character

local Scale = 4500

local mainCam

local function PlayCam(cameraPart)
	cam.CameraType = Enum.CameraType.Scriptable
	--cam.CameraSubject = playercharacter.Head
	mainCam = Run.RenderStepped:Connect(function()		
		local center = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
		local x = mouse.X - center.X / 2
		local y = mouse.Y - center.Y / 2
		local xOffset = x/Scale 
		local yOffset = y/Scale

		local lookAtPoint = cameraPart.Position+cameraPart.CFrame.LookVector*5
		local vector = Vector3.new(lookAtPoint.X - xOffset, lookAtPoint.Y - yOffset, lookAtPoint.Z - xOffset)  

		local result = CFrame.lookAt(cameraPart.CFrame.Position,vector)

		cam.CFrame = result
	end)
end
PlayCam(MaincamPart)

local function setPlayerCam()
	mainCam:Disconnect()
	--cam.CameraSubject = playercharacter.Humanoid
	cam.CameraType = Enum.CameraType.Custom
	cam.CFrame = playercharacter.Head.CFrame
end

Events.LoadMapUi.OnClientEvent:Connect(function(argument, map)
	if argument == "loading" then return end
		
	if map and map:FindFirstChild("camPart") then
		PlayCam(map.camPart)
	else
		setPlayerCam()
	end
end)

when i tried to use camerasubject or use run to loop through character limbs and set their transparency to zero:

is there any solution on this?
“sorry if i sucked at elaborating.”

2 Likes

It’s happening because when a player is in first-person, their BasePart’s LocalTransparencyModifier is set to 1. To fix this issue, you’ll need to check if the player is in first-person, and set the LocalTransparencyModifier to 0 if so, then set it back to 1 when the cutscene is finished:

local Run = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")

local mouse = game.Players.LocalPlayer:GetMouse()
local cam = workspace.CurrentCamera
local MaincamPart = workspace:WaitForChild("Map"):WaitForChild("camPart")

local player = game.Players.LocalPlayer
local playercharacter = player.Character or player.CharacterAdded:Wait()
local head = playercharacter:WaitForChild("Head")

local Scale = 4500

local mainCam

local isInFirstPerson

local function setLocalTransparency(value)
	for _, instance in playercharacter:GetDescendants() do
		if instance:IsA("BasePart") and instance ~= playercharacter.PrimaryPart then
			instance.LocalTransparencyModifier = value
		end
	end
end

local function PlayCam(cameraPart)
	cam.CameraType = Enum.CameraType.Scriptable

	if head.LocalTransparencyModifier == 1 then
		isInFirstPerson = true
		setLocalTransparency(0)
	end

	mainCam = Run.RenderStepped:Connect(function()		
		local center = Vector2.new(cam.ViewportSize.X/2, cam.ViewportSize.Y/2)
		local x = mouse.X - center.X / 2
		local y = mouse.Y - center.Y / 2
		local xOffset = x/Scale 
		local yOffset = y/Scale

		local lookAtPoint = cameraPart.Position+cameraPart.CFrame.LookVector*5
		local vector = Vector3.new(lookAtPoint.X - xOffset, lookAtPoint.Y - yOffset, lookAtPoint.Z - xOffset)  

		local result = CFrame.lookAt(cameraPart.CFrame.Position,vector)

		cam.CFrame = result
	end)
end
PlayCam(MaincamPart)

local function setPlayerCam()
	mainCam:Disconnect()

	if isInFirstPerson then
		isInFirstPerson = nil
		setLocalTransparency(1)
	end

	cam.CameraType = Enum.CameraType.Custom
	cam.CFrame = head.CFrame
end

Events.LoadMapUi.OnClientEvent:Connect(function(a, b)
	if a == "loading" then return end

	if b and b:FindFirstChild("camPart") then
		PlayCam(b.camPart)
	else
		setPlayerCam()
	end
end)
2 Likes

what about the plr character’s rotation?

the character is facing in 1 direction, like if you tried to move right or left, or back. it still faces in 1 direction, not rotating at all because he is still in first person.

do i need to script my own custom camera for this?

2 Likes

You can rotate the player’s character while the cutscene is playing by using the :PivotTo method and CFrame.lookAlong, like so:

playercharacter:PivotTo(CFrame.lookAlong(playercharacter:GetPivot().Position, -Vector.zAxis)) -- Replace -Vector.zAxis with your desired direction

Cutscenes do require temporarily taking control of the player’s camera, so technically yes, but your script is already doing so


@anos111 BTW I went ahead and rewrote the script, it should work identical to the current one but in a more efficient and safe way (as in, less likely to error since I made sure to use WaitForChild whenever appropriate), plus the script will now work even if the player dies or resets:

(The new script is quite long so I minimized it so my comment doesn't take up too much space)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

local camera = Workspace.CurrentCamera or Workspace:WaitForChild("Camera")

local events = ReplicatedStorage:WaitForChild("Events")
local loadMapUi = events:WaitForChild("LoadMapUi")

local player = Players.LocalPlayer
local mouse = player:GetMouse()

local character, head

local isInFirstPerson

local renderSteppedConnection

local function setLocalTransparency(value)
	for _, instance in character:GetDescendants() do
		if instance:IsA("BasePart") and instance ~= character.PrimaryPart then
			instance.LocalTransparencyModifier = value
		end
	end
end

local function playCamera(cameraPart)
	if renderSteppedConnection then return end -- Camera is already playing if a connection exists

	camera.CameraType = Enum.CameraType.Scriptable

	if head.LocalTransparencyModifier == 1 then
		isInFirstPerson = true
		setLocalTransparency(0)
	else
		isInFirstPerson = nil
	end

	renderSteppedConnection = RunService.RenderStepped:Connect(function()
		local center = camera.ViewportSize / 2
		local offset = Vector2.new(mouse.X - center.X / 2, mouse.Y - center.Y / 2) -- Don't know why you're dividing the center-point by 2 again, but I'll kept it just-in-case
		offset /= 4500

		local lookAtPoint = cameraPart.Position + cameraPart.CFrame.LookVector * 5
		local vector = Vector3.new(lookAtPoint.X - offset.X, lookAtPoint.Y - offset.Y, lookAtPoint.Z - offset.X)

		camera.CFrame = CFrame.lookAt(cameraPart.Position, vector)
	end)
end

local function stopCamera()
	if renderSteppedConnection then
		renderSteppedConnection:Disconnect()
		renderSteppedConnection = nil

		camera.CameraType = Enum.CameraType.Custom

		if isInFirstPerson then
			setLocalTransparency(1)
		end
	end
end

local function onCharacterAdded(newCharacter: Model)
	character = newCharacter
	head = newCharacter:WaitForChild("Head")
end

local function onLoadMapUiClientEvent(a, b) -- Do be sure to give variables descriptive names, as people helping you with your code don't know what a and b represent!
	if a == "loading" then return end

	if b then
		local cameraPart = b:FindFirstChild("camPart")

		if cameraPart then
			playCamera(cameraPart)
		end
	else
		stopCamera()
	end
end

onCharacterAdded(player.Character or player.CharacterAdded:Wait())

playCamera(Workspace:WaitForChild("Map"):WaitForChild("camPart"))

loadMapUi.OnClientEvent:Connect(onLoadMapUiClientEvent)
player.CharacterAdded:Connect(onCharacterAdded)
1 Like

Would calling CameraUtils.restoreRotationType() from the PlayerModule be a good idea to solve the rotation issue instead of CFraming? I tested it out and it seems to solve the rotation issue for me when the camera’s CFrame is changed while in first-person.

video (ignore the transparency thing):

3 Likes

That should work as well :slight_smile::+1:

2 Likes

okayy thats aactually genius and amazing, tysmm

local CameraUtils = require(player.PlayerScripts.PlayerModule.CameraModule.CameraUtils)

local function restoreRotation()
	CameraUtils.restoreRotationType()
end
2 Likes

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