Hello!

Lately I've been making a top down game with a custom camera. I've been having a problem with the camera though, I can't seem to get it to raycast correctly and move correctly up or down (depending on ceiling height). I'm not sure what the problem is but heres the code.

local cameraray = Ray.new(humanoidroot.CFrame.p,humanoidroot.CFrame.p + Vector3.new(0,maxY+1,0))

        local part,pos = workspace:FindPartOnRay(cameraray, playercharacter,true,true)

        if part then
            maxY = (pos - humanoidroot.CFrame.p).unit.magnitude + (part.Size.Y/4)
        end

        addY = minY + humanoidroot.Velocity.magnitude/10

        if maxY < 0 then
            maxY = maxY * -1
        end

        if addY >= maxY then
            addY = maxY
        end

        if addY < playeropacitydistance then
            for i,v in pairs(limbs) do
                if v then
                    v.Transparency = v.Transparency + 0.05
                    if v.Transparency > playeropacity then
                        v.Transparency = playeropacity
                    end
                end
            end
        else
            for i,v in pairs(limbs) do
                if v then
                    v.Transparency = v.Transparency - 0.05
                    if v.Transparency < 0 then
                        v.Transparency = 0
                    end
                end
            end
        end

Example of what it does ; https://gyazo.com/a99ce6ba3b96237251f540fe54d088be

5 comments

0

How exactly are you setting the CFrame of the camera? I figured that CFrame.new(rayHit, HumanoidRootPart) would have been enough, assuming that the camera already tracks your Character's position "horizontally".

0

Also, and I know that this is a design choice, but instead of moving the camera, why not just make the parts in-between the camera and the character semi-transparent? That's less jarring that whatever you're planning on doing, in my opinion.

0

Im using lerping with the end cframe of ; CFrame.new(humanoidroot.Position.X,humanoidroot.Position.Y + addY,humanoidroot.Position.Z). Secondly I'd perfer if the camera moved BUT I should probably try using part transparency

0

Mind trying CFrame.new(humanoidroot.Position, Vector3.new(humanoidroot.Position.X, pos.Y,humanoidroot.Position.Z)), where pos is where the ray hit? If your camera has a maximum height, then just use math.min(hit.Y, MAX_HEIGHT) as the y instead.

0

Sure