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

How would I make a smoother first person camera?

Asked by
Edenojack 171
8 years ago

So the current Roblox Camera code seems to skip tiny angles, this is really only noticable when reducing the field of view, or trying to move your camera in small increments.

I found one method was to simply change the camera from Pointing in the desired direction and instead lerping it towards its intended direction.

This smoothed the camera, but introduced roll. I used:

workspace.CurrentCamera.CoordinateFrame = workspace.CurrentCamera.CoordinateFrame:lerp(this.cframe,script.Parent.Parent.Stats.Zoom.Value)

this.CFrame is the new rotated camera CFrame. Zoom being how much the camera's field of view was divided by 20-30, to simulate lowering sensitivity.

While this works really well, it still jumps these small increments, and that is really annoying, ontop of also lagging behind the player.

I've read the wiki article, and tried to look about online to find a source on creating mouse movement, but sadly can't find anything. Does anyone know where I should start looking?

2 answers

Log in to vote
2
Answered by
Im_Nick 30
8 years ago

My personal way is using a custom lerp. (clerp) (Bit more advanced method)

local function clerp(p1,p2,percent)
            local p1x,p1y,p1z,p1R00,p1R01,p1R02,p1R10,p1R11,p1R12,p1R20,p1R21,p1R22 = p1:components()
            local p2x,p2y,p2z,p2R00,p2R01,p2R02,p2R10,p2R11,p2R12,p2R20,p2R21,p2R22 = p2:components()
            return 
                CFrame.new(p1x+percent*(p2x-p1x), p1y+percent*(p2y-p1y) ,p1z+percent*(p2z-p1z),
                (p1R00+percent*(p2R00-p1R00)), (p1R01+percent*(p2R01-p1R01)) ,(p1R02+percent*(p2R02-p1R02)),
                (p1R10+percent*(p2R10-p1R10)), (p1R11+percent*(p2R11-p1R11)) , (p1R12+percent*(p2R12-p1R12)),
                (p1R20+percent*(p2R20-p1R20)), (p1R21+percent*(p2R21-p1R21)) ,(p1R22+percent*(p2R22-p1R22)))
        end

http://wiki.roblox.com/index.php?title=Magnitude Example of my clerp.. (client)

local cam = workspace.CurrentCamera
local part1 = workspace.Part1
local char = workspace:WaitForChild(game.Players.LocalPlayer.Name)
local rs = game:GetService("RunService").RenderStepped

cam.CameraType="Scriptable" -- Make the camera scriptable

for i = 1, ((part1.Position - char.Torso.Position).magnitude), 1 do
    cam.CoordinateFrame = clerp(
        cam.CoordinateFrame,
        part1.CFrame
    ,.02)
    rs:wait()
end

-- HOW MY CLERP WORKS -- It runs all off of CFrame, thus to change the camera position. (VERY smoothly) http://wiki.roblox.com/index.php?title=CFrame http://prntscr.com/ajzsh1

Lets use CoordinateFrame because it runs on CFrame.

camera.CoordinateFrame 

Now, since my clerp returns a CFrame, we need to do this..

camera.CoordinateFrame = clerp( a, b, c )

The first arg of my clerp needs to be a CFrame, the CFrame we will be using

camera.CoordinateFrame = clerp( camera.CoordinateFrame , b, c )

The second arg of my clerp need to be the CFrame YOU WANT

camera.CoordinateFrame = clerp( a , CFrame.new(9,576,50) , c )

The last bit of my clerp (#arg 3) needs to be a decimal. Such as .01 - 1 This last arg will determine how quick the (and smooth) the movement will be

camera.CoordinateFrame = clerp( a , b , .02 )

I have already set up the correct camera interpolation decimal, but change it if you need. :)

1
Inefficient :c User#6546 35 — 8y
0
Not really, clerps are MUCH faster then normal lerp. Plus its just smoother. The for i loop I made quickly because Im on tablet lol Im_Nick 30 — 8y
0
Least I took my own time and will into making a custom lerp. Im_Nick 30 — 8y
0
So what's the difference between clerping all the constructors of a CFrame rather than doing it with just the X,Y,Z Coords and eulear angles? LateralLace 297 — 8y
0
With a clerp you can pick and choose perfect angles while getting the smoothest usage possible. X.Y.Z could be used I would guess, but not as smooth as a custom clerp. Im_Nick 30 — 8y
Ad
Log in to vote
-2
Answered by 8 years ago

this works for some people

http://www.roblox.com/Custom-First-Person-Camera-item?id=109009588

this also may be able to help you

http://www.roblox.com/CameraPlus-item?id=151771886

Answer this question