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

How can I rotate the camera as the character turns?

I'm trying to create a custom over-the-shoulder camera, that rotates (left to right) respective to where the character turns. This is what I have so far: https://gyazo.com/82afc182da2a3ec664fe3c14f377fd83

I'm not sure how I can rotate the camera to the direction the character is facing, while maintaining the same over-the-shoulder stature. If anybody could share their insight on this, I'd really appreciate it!

2 comments

0

Well have you played around with the camera object in Workspace? Go into a test server then try all of the different cameratypes by opening properties with the camera object selected. One of them should fit your needs.

0

Unity, I've made my custom camera and none of those can really help me in my situation. Thank you anyways.

1 answer

hmm, that's a bit tricky. I'm not that good with cframes, but you gave a good description of what you're trying to do which makes me confident my attempt may be your solution

local runService = game:GetService'RunService'
local userInput = game:GetService'UserInputService'

local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local head = char:WaitForChild'Head'

camera.CameraType = 'Scriptable' -- set camera to scriptable I assume, if it's a custom camera?

local camOffset1 = Vector3.new(3,1,0) -- define offset from player
local camOffset2 = Vector3.new(0,2,7) -- define offset from last offset

runService.RenderStepped:Connect(function()
	local lookAt = head.CFrame * CFrame.new(camOffset1) -- the offset away from the player that the camera will look at
	camera.CFrame = lookAt * CFrame.new(camOffset2) -- the distance away from the look at point
	camera.CFrame = CFrame.new(camera.CFrame.p, lookAt.p) -- force camera to look at second offset
end)

Explanation

basically the logic behind all of this, is that you first define your shoulder offset. once you have that center point, you offset it again by how far back you want the camera away from the character. and the last line camera.CFrame = CFrame.new(camera.CFrame.p, lookAt.p) just makes sure the camera stays tilted towards the center point. hope this helped.

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