Moving CurrentCamera up slightly

Hi guys,

Basically I want my game to have the camera always be centered a stud or two above the player. The closest thing I could find to what I am looking for is Shindo Life’s camera.
https://gyazo.com/918b622a5864549c23a0a3e7372a782c

I already have the camera locked on the player, and the player rotating with the camera, but I cannot seem to figure out how to get the camera to be slightly above the player’s head, while still maintaining control over zoom level and movement.

I basically just want the camera to be exactly like this, but raised slightly up.
https://gyazo.com/3847b8234549677bd0db0887d3c17e69

Edit:
I have tried multiple things like this, but none seem to move the camera at all.

local baseCamPos = cam.CFrame.Position
baseCamPos = baseCamPos + Vector3.new(0,5,0)
2 Likes

You’re on the right track, just remove .Position on the first line since Position isn’t a valid property of camera and therefore can’t be assigned to. If you want to modify the position you have to set it’s CFrame. Also, not sure if you’ve done this or not but make sure this is wrapped in a RenderStepped event.

local baseCamPos = cam.CFrame
baseCamPos = baseCamPos + Vector3.new(0,5,0)
1 Like

What do you have the CameraType set to? Seems like Attach would be best for your case.

1 Like

I would imagine that you are saying do something like this, but it doesn’t seem to work.

local baseCamPos = cam.CFrame

game:GetService("RunService").RenderStepped:Connect(function()
	if baseCamPos == baseCamPos then
		baseCamPos = baseCamPos + Vector3.new(0,5,0)
	end
end)

Correct, although I’m not sure what that conditional statement is for. Make sure that you do what @Scottifly said and change the CameraType.

1 Like

I’m not sure how to check that, but I haven’t changed it so whatever the base setting is

Wouldn’t you need to put
local baseCamPos = cam.CFrame
inside the event to make it update each step?

2 Likes

API, API, API…

Humanoids sport a property dubbed “CameraOffset” which is a Vector3 datatype. Try setting that to 0, 5, 0 upon respawn and see if that does the trick.

3 Likes

Okay CameraType is Custom

Summary

And I have update the script to this, but am not noticing a change

game:GetService("RunService").RenderStepped:Connect(function()
	local baseCamPos = cam.CFrame
	baseCamPos = baseCamPos + Vector3.new(0,5,0)
end)

Have you tried changing Custom to Attach?

1 Like

What @HollowMariofan said might actually be the better solution for this particular issue so that you can keep whatever cameratype you want without having to mess with the cameratype at all. Didn’t even know that that propety existed.

1 Like

But if you kept it Custom the player would still be able to spin around without turning the camera, which is not what the first gyazo video shows.
That first video has the camera firmly attached to the player which is why I pointed out the Attach CameraType.

1 Like

I have this set through this script:

game:GetService("RunService").RenderStepped:Connect(function()
	if plr.Character then
		local rootPart = plr.Character:WaitForChild("HumanoidRootPart")
		if rootPart then
			rootPart.CFrame = CFrame.new(rootPart.CFrame.p, rootPart.CFrame.p + Vector3.new(cam.CFrame.LookVector.X,0,cam.CFrame.LookVector.Z))
		end
	end
end)

So this is only my 3rd day coding and I don’t know that much about it;

I would do something like this?

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local camOffSet = humanoid.CameraOffset


local function onCharacterAdded(character)
	camOffSet = Vector3.new(0,5,0)
end

Setting camOffset to humanoid’s CameraOffset creates a local variable that won’t tamper with anything outside of the script. In order to change that property, you’ll have to set it directly:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local function onCharacterAdded()
	humanoid.CameraOffset = Vector3.new(0, 5, 0)
end

Make sure this is a LocalScript, too. Is this the entirety of your code or is this just a chunk & you call onCharacterAdded somewhere else in the script?

1 Like

Do you have to change the CameraType Property when respawning too, or can it just be set in the Properties window of the Camera in Studio?

I changed the script to what post:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local function onCharacterAdded()
	humanoid.CameraOffset = Vector3.new(0, 5, 0)
end

However, the CameraOffset does not seem to be moving:

EDIT:
removed character from the onCharacterAdded function incase that was an error

Ah, my apologies; I thought you were just sending me a small chunk of your completed code.

You’ll have to “call” that function because that code is stored & idling in a memory address. However, I think it would be best to remove the function block and instead just have that code run at startup:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
humanoid.CameraOffset = Vector3.new(0, 5, 0)

There’s certain things I would do different in terms of syntax use, but I’ll leave those things out for now. The code above should run as intended.

Addressing what @Scottifly added: yes, you would need to change the CameraType upon respawn but I’m under the assumption that you have the actual character-locked-to-camera ordeal down.

1 Like

Ahh okay, the script is working fine now:

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

humanoid.CameraOffset = Vector3.new(0, 2, 0)

Results:
https://gyazo.com/9049214d26374455ca66b5821d0d3dbe

Thanks to @HollowMariofan @Scottifly @azlentic for help!

3 Likes

Great work. Good luck on your project!

1 Like