Camera Manipulation Help

Hello,
I want to make it where my camera cannot move, and will only show the front of my avatar. As well as that, my character can only move up and down. How would I approach this?

1 Like

One way you could do this is by binding a RenderStep loop to always be in front of the character (via head or torso lookvector), and to make a custom movement system for letting the character move up and down.

Could you send me a reference source to make this? I’m not sure how I would script it out.

For the camera, you would do something like this:

--StarterCharacterScripts LocalScript

local RunService = game:GetService("RunService")

local Camera = workspace.CurrentCamera

local Head = script.Parent:WaitForChild("Head")

local CFNew = CFrame.new

RunService:BindToRenderStep("SetCamPos", Enum.RenderPriority.Camera.Value, function()
   Camera.CameraType = Enum.CameraType.Scriptable --forgot to add, sorry
   Camera.CFrame = CFNew(Head.Position + (Head.CFrame.LookVector * 5), Head.Position)
end)
1 Like

I have a question, what do you mean by you want the character to only move up and down?, do you mean the camera or the actual character

I believe he means like a 2D game (Mario for example) where you can only move left and right.

2 Likes

Hello, @zQ86 your script didn’t work as I intended it. When I move, I spin around and the camera doesn’t stay in place. Perhaps I also need a forward and backwards script as well.
Edit: I’ll try to create a video of it. I want it like mario.

2 Likes

Ah yes, sorry. If you want the Camera to be in some position in front of the player, you would do something like this instead.

RunService:BindToRenderStep("SetCamPos", Enum.RenderPriority.Camera.Value, function()
   Camera.CameraType = Enum.CameraType.Scriptable
   Camera.CFrame = Head.CFrame * CFNew(3, 0, 0) --or whatever you want to set it to
end)

@zQ86

What if instead of this, I instead change the camera from a distance?

I don’t really understand what you are trying to say. What do you mean?
(also, you don’t have to mention me for me to reply to you, i get the notification)

if you the character only go left and right like Mario you could do something like this:

---localscript in StarterPlayerScripts
local player = game.Players.LocalPlayer
local Character = player.CharacterAdded:Connect(function(Character)
local Root = Character:WaitForChild("HumanoidRootPart")
local lastZpos = Root.CFrame.Z
local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
if lastZpos ~= Root.CFrame.Z then
		Root.CFrame = CFrame.new(Vector3.new(Root.Position.X, Root.Position.Y, lastZpos)) * CFrame.Angles(0, math.rad(Root.Orientation.Y),0)     -- limits the z axis, but maintains the orientation of the HumanoidRootPart
		lastZpos =  Root.CFrame.Z
	end
 end)
end)
1 Like

Okay, I was directing my question towards you.
For example:

You could use a NumberValue or IntValue (or just a local variable) to track how far away you want the Camera to be on any sort of axis.

Should I attach my camera to the glass wall or something or is using fieldofview enough?

Hello Jaycbee,
Your script didn’t work. I tested your local script and nothing happened.

You can use FieldOfView if you want, but I would suggest using CFrame.new() multiplication logic.

i updated it, but it should still have worked, if it was in StarterPlayerScripts

Hello, did I do something wrong? Does the script need to be named something because I got everything correct.
image

That’s weird , It’s working for me, but keep in mind that you might need to flip the axis, (Z to X), because the script i provided locks the Z axis of the player. Assuming that the camera is not going to be able to be moved by the player, (so that the camera is facing a different direction relative to the player) as that’s is similar to how 2d/Mario cameras look/work, you should by able to “manually” adjust the axis the player cannot move in. (if that makes sense)

Example
local player = game.Players.LocalPlayer
local Character = player.CharacterAdded:Connect(function(Character)
local Root = Character:WaitForChild("HumanoidRootPart")
local lastXpos = Root.CFrame.X
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

RunService.Heartbeat:Connect(function()
if lastXpos ~= Root.CFrame.X then
		Root.CFrame = CFrame.new(Vector3.new(lastXpos, Root.Position.Y, Root.Position.Z )) * CFrame.Angles(0, math.rad(Root.Orientation.Y),0)     -- limits the z axis, but maintains the orientation of the HumanoidRootPart
		lastXpos =  Root.CFrame.X
			
	end
 end)

end)

Alternatively if you wanted to completely disable left and right movement, you can use the ContexActionService

You are doing Player.CharacterAdded:Connect(function(Character) instead of Player.CharacterAdded:Wait(). Plus, the character could’ve already been initialized by the time the script has ran.
Do this instead.

local Character = player.Character or Player.CharacterAdded:Wait()