Hello. I’ve made a simple planet, on which you can place buildings and connect them together(Modular bases). There’s a glass connection, made out of few parts which appears after connecting. It should be perfectly aligned, but sadly, its laying on its side:
The base is around the north pole of the planet, so it’s only slightly oriented relative to orientation(0,0,0). The connection is of course made using CFrame.lookat. I need help with fixing it, so it aligns normally everywhere on the planet. Thanks for help!
Normally it should look like this:
code?
The frame looks to be in the same relative orientation in both images? I don’t see a difference except for the glass part, which kind of makes it look like it’s maybe just an unanchored or unwelded piece of the model that just fell out.
Also, this “planet”, is it something unusual like a Ball part with custom gravity, or is it just a normal-gravity situation, it’s unclear.
Lastly, is look-at even necessary? If the connecting tunnel is oriented correctly, can you just copy the orientation to the glass part, or just weld it? CFrame.lookAt has some singularities you need to account for.
Firstly, the first image is taken around the poles of the planet, so the orientation is around (0,0,0) and the second image is near the equator, so it’s around 90 degrees. The planet is a 3d terrain ball, customly generated and smoothened. Lastly, look at is necessary, because the modules, that player place, aren’t perfectly in line, player can place them like this:
or like this:
The tunnel needs to be connected, even when the second module is orientated, or is far away. The issue, I am having, is with CFrame.lookat, it fails to orientate the connection perfectly, and the connection isn’t accessible.
Other parts of the script aren’t necessary, they just include other parts being resized and put near the main part
local middle = pos1:Lerp(pos2, 0.5) -- pos1 is a point where the connection starts(the round building), pos2 is where it ends.
local up = connectorpart2.CFrame.UpVector*10 -- this is the up vector of the part, that is being placed, when the connection is being created
mainpart.CFrame = CFrame.lookAt(middle, connectorpart2.Position, middle+up) -- and i am having issues with this
okay just out of curiosity
why are you using cframe.lookat for this? why lerp?
Alright so: Lerp, is to determine a point in the middle of these two connector parts(Parts which the connection is between), so I can place the connection in between, I am also using CFrame.lookat because the player can’t place the buildings in a perfect line, so I need to determine orientation that the connection should face, for it to align perfectly with the other building.
i am pretty sure you should be multiplying the Unit
of the UpVector
, not the vector itself
unless that doesn’t make a difference…
why make it look at middle+up
, shouldn’t you be making it look at up
only?
also, you are doing middle+up
, where middle
is a CFrame
and up
is a number
i am pretty sure the up
variable doesn’t even get added properly (let alone with the fact you can’t add to cframes, only multiply)
just grasping straws at this point, but it’s something to do with the way you make it look at the given point
It’s working now, thank you. I’ve been searching for the solution for a few days now.
wait what was the fix
Are you sure that the up is actualy up? The up vector you’re using might actualy be forwards or right.
local middle = pos1:Lerp(pos2, 0.5) -- pos1 is a point where the connection starts(the round building), pos2 is where it ends.
local up = connectorpart2.CFrame.LookVector -- you don't need the multiply and i switched it to lookvector maybe thats actualy up :shrug:". this is the up vector of the part, that is being placed, when the connection is being created
mainpart.CFrame = CFrame.lookAt(middle, pos2, middle+up) -- pos2 should be fine. and i am having issues with this
Yes i am aware your problem is already solved but i am finishing my response anyway.
Its uhhhhhh the… deleting the middle
and leaving only up
It was just facing the same direction at every point on the planet, something was just wrong. But I got the fix already.
Yeah, that 3rd argument to LookAt has to be a direction vector, specifically the desired UpVector of the resulting CFrame. LookAt is internally doing a cross product with that to get the right vector of the CFrame it returns.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.