#Help with viewport Camera Calculation math(idk what to call this)

1 messages · Page 1 of 1 (latest)

edgy pewter
#

I'm working on a system like no man's sky for seamless transition between interplanetary space and going into the planet with no loading screens i mostly got the planet generation down with a chunk system and some perlin noise(the image should kinda look like pluto)

What I'm currently working on is rendering the planet when your in interplanetary space
the way i do this is i have an invisible part follow the player so it doesn't derender when u are far away and attached a billboardgui and then viewportframe and scale the billboard so i can get past the max part limit
but now i have to calculate what the viewport should show if you are looking at it which i do with this code

local cameraDistance = 1
local planet = workspace:WaitForChild("Planet")
local planetPosition = Vector3.new(0,0,-10)


game:GetService("RunService").RenderStepped:Connect(function()
    planet.Position = playerRoot.Position
    
    local playerCam = workspace.CurrentCamera.CFrame
    local dir = (playerCam.Position - planet.Position).Unit
    local camPos = dir * cameraDistance

    vpCam.CFrame = CFrame.lookAt(camPos, Vector3.new(0,0,0))
    
    local offset = planetPosition - playerRoot.Position
    billboardGui.StudsOffsetWorldSpace = offset
end)

it kinda works as you can see in the videos but the bigger the planet is the more you can see wrong
idk why it is like that but I'm tired and have a fever and am being stupid right now

I left a ms paint image i made in like 5 seconds to show should be happening but most likely looks scribbles

if someone could point out why my code is bad or recommend a different way to render planets much thanks would be appreciated

ps: mb if this all sounds like yapping or gibberish

#

im going to sleep now

#

when i wake up hopefully a smart person would have figured this out

idle edge
#

i don't have your answer but i just appreciate the actual, rare good quality scripting help post

left tangle
# edgy pewter I'm working on a system like no man's sky for seamless transition between interp...

So I would advice just using the age old optimization trick: levels of details
e.g. a game, with a nice building, from upclose you can see all the details, then from far away you think that you see the same mesh, but in reality it's a very simplified version of it (as seen with the bunny in pic1).

Then, as for the scale, I do partially like moving the model around to not cause it to not render. You can look at something similar to what the game (steam game) Subliminal does. Scaling based camera position. Basically, you can use the inverse square law to determine how large your object has to be, to appear the same as an object that's a certain size, but closer to the camera.
Now you can use that to fake the distance without it derendering (pic 2 shows the inverse square law, in cause you do not know it yet(technically to calculate light, but vision is light based 😉 ))

edgy pewter
left tangle
edgy pewter
left tangle
edgy pewter
left tangle
edgy pewter
left tangle
edgy pewter
hasty shadow
#

Ok nevermind they do 🐧

edgy pewter
#

part size limit

hasty shadow
#

Ohhhh

edgy pewter
hasty shadow
#

Ur cooked then 🙏

tough bayBOT
#

studio** You are now Level 7! **studio

edgy pewter
#

ik

#

gonna go see if ai can fix this

#

last resort

#

wait

#

i think i found the probleem

#

basically
local dir = (playerCam.Position - planet.Position).Unit
should be
local dir = (playerCam.Position - planetPosition).Unit

i forgot to change it when i started making the planet follow the player for infinite view distance

#

im really stupid

#

i am now see some problems with having it be ui

edgy pewter
#

theres still some problems with it being ui