Camera orientation returning a different value
I’m currently making a generic simulator to learn scripting and stuff, atm i’m trying to set viewports with a new camera instance however i’m having problems with a camera not setting the correct value within the CFrame.Orientation, i’m feeling kinda dumb ngl
--//Camera
local Camera = Instance.new("Camera")
Camera.Name = "PetViewGacha01"
Camera.Parent = game.Workspace
Camera.CameraType = "Scriptable"
local Pos = Vector3.new(560.316, 2.484, 192.123)
local Lookat = Vector3.new(1.36, -78.234, 0)
local function updateCam()
Camera.CFrame = CFrame.new(Pos, Lookat)
end
--//Settings
local Mainframe = script.Parent.MainFrame
for _,v in Mainframe:GetChildren() do
if v:IsA("ViewportFrame") then
v.CurrentCamera = Camera
end
end
while true do
task.wait(0.5)
updateCam()
end
The CFrame.Orientation should be set as (1.36, -78.234, 0) but is returning (-7.777, 71.031, -0) instead
Someone knows how to fix that?
1 Like
Are you getting any error though ?
1 Like
Maybe try to set CFrame.Orientation indivisually.
1 Like
I’m not getting any errors on the output
1 Like
Tried it before and didnt worked
1 Like
I think maybe your misunderstanding what your script is doing. You’re using the Lookat variable as a position the camera should look at, from a different position. Therefore you aren’t setting the orientation with the Lookat variable.
There’s also no reason to update the camera every second because it never changes position.
2 Likes
This is one of the alternative that i’ve tried, this is my first time working with cameras so i dont really know how to configure them.
I know, i added it to see how it debugs, i forgot to remove it from this topic
Alright, well I don’t think you really need those variables. Just make a camera for the viewportframe like this:
local viewcam = Instance.new("Camera")
viewcam.CFrame = CFrame.new(Vector3.new(0,0,-10), Vector3.new())
viewcam.Parent = ViewportFrame -- might not need to use this line
ViewportFrame.CurrentCamera = viewcam
-- Place the object at the origin, the camera should look at the object.
You shouldn’t parent camera for viewportframes in the workspace. Keep it in nil or the viewportframe instead!
I also recommended using WorldModels to allow fluid animations in the viewportframe. Otherwise, the image will be frozen until a property of the viewportframe changes.
1 Like
Alright! I’ll test here, brb
Uhhh…If we try it using a basic part, I’m just guessing that if we’re using LookAt, it orientated to look so the orientation should change.
Can you tell me one thing, is the camera looking at where it is supposed to ?
Because LookAt just looks at the position, orientation can be anything I guess. If this doesn’t helps, maybe try CFrame.lookAt
Nope, it’s supposed to look like this:
But still there’s a question in my mind, you setted the orientation, so it should orient accordingly.
I have used my most of the brain ever to solve this problem
Yeah but the orientation is setting as -7.777, 71.031, -0 instead of 1.36, -78.234, 0
Yeah I see, I do hope anyone could help.
1 Like
May I ask why these numbers are decimals? Can it be simple instead? I assume it’s just a viewportframe with a camera looking at an egg, after all.
Uhhh…I don’t think decimals should be a problem tbh. But yeah, if you do want to show pets, just multiply the lookVector by some studs.
Just saying that the position and orientation seem pretty random, and they should be at the origin instead, to keep things clean and understandable.