Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Rotating camera to where the character is?

Asked by 9 years ago

EDIT: To further explain, I have attempted to make a picture of what I want to do, this can be viewed here.

Hi all, I have the following script at the moment which gives a top-down view of my playing surface for my game.

game.StarterGui:SetCoreGuiEnabled("All",false)
game.StarterGui:SetCoreGuiEnabled("Chat",true)

repeat wait() until _G.Players
Players = _G.Players

function findPlayer(plr)
for i,v in pairs(Players) do
if v == plr then
return i
end
end
return false
end

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local plrNum = (findPlayer(player) ~= false) and findPlayer(player) or nil
repeat wait() until camera and plrNum ~= nil

camera.Focus = game.Workspace["Playing Surface"]["Chair"..plrNum].Seat.CFrame
camera.CameraType = "Scriptable"
camera.CoordinateFrame = CFrame.new(game.Workspace["Playing Surface"].Table.Position + Vector3.new(0,15,0)) * CFrame.Angles(math.rad(-90),0,0)

It works, but I want it so that the camera is the same rotation of where the character is sitting around the table, so that the player's character is always near the bottom of the screen. Right now, the position of the player on the camera corresponds to the player number property.

P1 = Right of the screen.

P2 = Bottom of the screen (where I want all of the players' characters to be on their screen.)

P3 = Left of the screen.

P4 = Top of the screen.

Any help is appreciated, thanks.

0
Just create an invisible Part with the correct CFrame, then set the camera's CFrame to that. Perci1 4988 — 9y
0
I've tried to simplify my problem by adding a picture, check my edit. Spongocardo 1991 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

Well, you can simply use setRoll(angle) method of the camera. It would look something like this:

camera:setRoll(-90+90*(playerNum-1))

If that doesn't rotate the camera properly, just play around with the numbers, but I think this should be alright.

Ad

Answer this question