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

Third person camera?

Asked by
drahsid5 250 Moderation Voter
8 years ago

I'm trying to create a third person camera and cannot get it to rotate around the player properly. What I am doing is taking the mouse.Delta as a way to add or subtract the angle of rotation. My problem is it will not rotate around the player, and if I allow the y axis to be rotated, it will be able to be rotated to unusable angles (It can flip upside-down and whatnot) I have tried to add and subtract the Z according to the rotation amount but that probed unreliable. I also tried to use CFrame:toObjectSpace() and couldn't get that to work.

My code:

--Camera update--
    game:GetService("RunService").RenderStepped:connect(function()
        if player.Self == nil then return end
        cam.CoordinateFrame = player.Self.Head.CFrame*CFrame.new(0,1,7)*camera.offset
    end)    
--Input--
    inp.InputChanged:connect(function(io)
        if io.UserInputType == Enum.UserInputType.MouseMovement then
            camera.offset = camera.offset*CFrame.Angles(0,-math.rad(io.Delta.x/10),0)
        end
    end)
0
Why don't you NOT use RenderStepped? And what is cam? You haven't named it. ScriptFusion 210 — 8y
0
If I didn't use RenderStepped the camera would be laggy as it updated. And I have named it in the code before. cam = player.Camera, player.Camera = game.Workspace.CurrentCamera. drahsid5 250 — 8y

1 answer

Log in to vote
0
Answered by
Jexpler 63
7 years ago

Watch this, it explains how to force first and third person cameras and explains how they work: https://www.youtube.com/watch?v=kyJZxVJZpHg

Ad

Answer this question