How to make the player's camera locked on player's body rotation and position?

Hello! I need help with scripting the player’s camera so it is in first person, but they can’t move their camera, the only way to move their camera would be moving their character, which would make the camera face the same way as their character, basically how Maze 3D’s (The Window’s 95 screensaver) camera works.

Example of what I want to recreate:
CC ROI | LAGreenHairAnimation60off | 16x9

I tried doing this before using the following script (Since I dont exactly know how the camera works):

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Fixed
camera.CFrame = player.Character.Head.CFrame

Which didn’t work, I tried looping to see if that fixed the script but that didn’t work either, I also tried looking in the forum for similar posts to mine to see if anyone had already figured out but whatever I found didnt fully fit what I’m looking for.

I’m a very begginer dev, and have little to no experience with cameras, so patient and helpful guiding, and constructive criticism would be very appreciated

4 Likes

LOOK IT UP!

Scripting support is NOT for getting entire systems. LOOK IT UP ON GOOGLE, YOUTUBE, THE DEV FORUM, ETC. STOP ASKING FOR THIS STUFF, THIS ISNT WHAT THE FORUM IS FOR.

Please please please use the resources at your disposal before asking. You havent even attempted to do this.

Sorry but that is a extremely uncalled for and aggresive response, and a stretch.

I have attempted it before, or else I wouldnt be here, I tried making the camera constantly stay on there torso and match it’s rotation and it didnt work, I looked it up and nothing seemed to fit what I wanted.

You are not helping at all, and if you cant help in a post where someone needs help with a script that isnt working, dont say anything at all…

I wasnt looking for a entire system, I was looking for someone to help me understand how it works or how to make it, which is WHAT THE ENTIRE PURPOSE OF SUPPORT IS, you are the only person to be mad AT SOMEONE ASKING FOR SUPPORT IN A SUPPORT FORUM.

What script do you need help with? There is no code that is included with your post, which is required, your post does not follow any of the posting guidelines either. Either edit the post with the required information, or delete it all-together.

Also my reply was not aggressive in any way. I am helping you by leading you to the correct resources.

You VERY CLEARLY have tone blindness apparently, and you are NOT helping at all, but i’ll give you the benefit of the doubt.

Since I dont exactlt understand how the camera works, I tried using the following script:

local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")

local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera

camera.CameraType = Enum.CameraType.Fixed
camera.CFrame = player.Character.Head.CFrame

Thinking it would follow stay on the head, that didnt work so I tried looping it, but that didn’t work either, I looked up people asked for similar things but the camera could still move freely even in first person, and even after looking at the documentation I still don’t know how to do what I’m looking for.

Okay, so we first want to set the CameraType to Enum.CameraType.Scriptable

Having the camera type as fixed means the camera will stay in one position and never move (IIRC you cannot script the camera while it’s in this state), then you want to use RunService to constantly set the camera to the head’s CFrame with an offset each frame.

local RunService = game:GetService("RunService")
local Camera = workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable


RunService.PreRender:Connect(function()
    -- Camera Logic in here.
end)

RunService.PreRender fires every time right before the frame renders. Try to get the offset done, which should prevent any rotation as well. Once you have that working then I’ll help you further.

Resources:

1 Like

Thanks! Got it working exactly how I wanted,

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Char = Players.LocalPlayer.Character
local Camera = workspace.CurrentCamera

Camera.CameraType = Enum.CameraType.Scriptable


RunService.PreRender:Connect(function()
	Camera.CFrame = Char.HumanoidRootPart.CFrame
end)

The only problem I’m facing is that the avatar itself obstructs the player’s pov/view, I already know that locking the player in first person fixes this, but I want the player to be still able to move their mouse in order to click UI buttons.

I also tried to fix this using an UI button, which did free the mouse, but it also made it unable to click other buttons.

Correct, so are you looking for a first-person or third person view?

Keep in mind that when you set the CFrame of the camera to the CFrame of a BasePart there will be obstructions. The reason that you don’t have obstructions when locking first person or going first person normally is a BasePart property called LocalTransparencyModifier, which modifies the transparencies of parts while in first person.

You can fix this by setting the LocalTransparency modifier of the part that “houses” your camera to 1
BasePart.LocalTransparencyModifier = 1 or by setting a small offset forward using CFrame math.

i.e HumanoidRootPart.CFrame * CFrame.new(1, 0, 0) for a 1 stud offset in the X axis relative to the part

Idk if this will help but I have created a Module to help with manipulating the camera this way actually. It was originally created for a top-down view of the player, but with a small edit to the module you can actually set it to be the head that the offset is relative to. Just change inside the
Update function to use the head instead of Humanoid RootPart.

Usage:

local CameraService = require(--[[Wherever the camera is]])
CameraService.new() -- You could provide the camera here, but the module does not require it.

CameraService:SetOffset(CFrame.new(0,0,0)) -- Set the offset to the offset you actually want, this is a CFrame value, do not include the head CFrame here. With (0,0,0) you are essentially setting no offset.  Play around with this to find your perfect offset.

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local Camera = {}
Camera.__index = Camera

function Camera.new(targetCamera)
	local self = setmetatable({}, Camera)
	self._cam = targetCamera or workspace.CurrentCamera
	self._offset = CFrame.new(0, 10, 15)
	self._localPlayer = Players.LocalPlayer
	self._rotateWithPlayer = false

	if self._cam then
		self._cam.CameraType = Enum.CameraType.Scriptable
		RunService.RenderStepped:Connect(function()
			self:Update()
		end)
	else
		warn("CameraManager: Camera object not provided or workspace.CurrentCamera is nil at initialization.")
	end

	return self
end

function Camera:Update()
	-- Ensure LocalPlayer is available
	if not self._localPlayer then
		self._localPlayer = Players.LocalPlayer
		if not self._localPlayer then
			return
		end
	end

	local character = self._localPlayer.Character
	if character then
		local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			if self._rotateWithPlayer then
				self._cam.CFrame = humanoidRootPart.CFrame * self._offset
			else
				self._cam.CFrame = CFrame.new(humanoidRootPart.Position) * self._offset
			end
		end
	end
end

function Camera:SetRotateWithPlayer(shouldRotate: boolean)
	self._rotateWithPlayer = shouldRotate
end

function Camera:SetOffset(new_offset: CFrame)
	self._offset = new_offset
end

function Camera:SetZoom()
	-- TODO: Add zooming functionality.
end

function Camera:Reset()
	if self._cam then
		self._cam.CameraType = Enum.CameraType.Custom
	end
end

return Camera
1 Like

Yes, I am looking for a first person view, so I can recreate how old 1990~ shooter game looked/worked, since the player will be using a StarterCharacter I been thinking of simply making the character invisible.

I sadly do not know how to apply the LocalTransparencyModifier into the script though.

Check my edit to my recent reply. Also setting the LocalTransparencyModifier can only be done on a local script. and you just get a reference to the part, then do part.LocalTransparencyModifier = whatever value you want here

1 Like

I think I can work with this, thank you!

1 Like

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