Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my camera fail to focus on the player?

I am attempting to create a "Bird's Eye View" camera. Setting the camera's coordinate frame to above the character's head works properly, but setting the focus does nothing. What am I doing or not doing that prevents my camera from looking straight down onto the player?

The script:

camera = game.Workspace.CurrentCamera
camera.CameraType = "Scriptable"

player = game.Players.LocalPlayer
repeat wait() until player.Character
character = player.Character

game:GetService("RunService").RenderStepped:connect(function()
	wait()
	camera.CFrame = CFrame.new(character.Head.Position + Vector3.new(0,10,0))
	camera.Focus = CFrame.new(character.Head.Position)
end)

1 answer

✓ Accepted answer

Two problems:

1.

It is camera.CoordinateFrame, not camera.CFrame. I don't know why it is not CFrame.

2.

CFrame has two values; a position value and a rotation value. The rotation value is a Vector3 value, and is called 'LookVector'. For example, the following code would position a part and make it look at the second part.

part.CFrame = CFrame.new(Vector3.new(0,0,0),part2.Position)

So, your code would be the following:

 camera.CFrame = CFrame.new(character.Head.Position + Vector3.new(0,10,0),character.Head.Position)
-- the camera.Focus isn't needed

Also, you may find camera.Interpolate() useful in these circumstances, as it is basically the tweening of cameras.

Hope I helped! Please tell me in the comments if you need more help.

~TDP

8 comments

0

The camera now works as it is supposed to, but I am unable to move my character...

0

You should. It's probably just a studio bug, Try again. Are you running any other pieces of code that may interfere with this?

0

No, just the above as I had it before with the lookVector added to the CFrame of the camera.

0

So, it worked before? Try disabling the camera script and see what happens.

0

The one that's automatically in PlayerScripts? I've already disabled the one I'm messing around with, and the camera goes back to normal, and I can move.

0

I'm not sure, sorry. The code above doesn't change anything to do with the character, I've done this hundreds of times.

0

I found through testing that if I put the camera anywhere but above the player, my player can move. However, when I put it directly above the player (what I need), I can only jump.

0

I think I'm just going to re-script the movement (I probably would have had to for the game eventually anyway). Thanks for all your help!

This discussion is preserved as it was. New answers, comments, and votes are closed.