Hey, so I am trying to re-create an airbus A320 PFD(if you don’t know what a PFD is, it is a Primary Flight Display that shows airspeed, altitude etc.).
I have a template I have tried to go off, except I cannot manage to make it work.
When a block is rotated (shown below), the rotation of the ground/sky rotates. I would like it to be almost realistic as possible to the IRL one in an A320.
What about grabbing the X/Z orientation and connecting that to the
Surface UI?? via heartbeat/renderstepped
And then the UI rotation is the same as the part rotation
Edited to correct this paragraph because I’m a moron.
I think this is probably what you are looking for. This only handles the roll on the Z axis in radians as it will be required to rotate the GUI, but you can adapt it to get the pitch as well.
local function GetRollAngle(orientation:CFrame)
local target:Vector3 = orientation.ZVector:Cross(Vector3.yAxis)
local angle:number = math.pi-math.acos(target:Dot(orientation.XVector))
if orientation.RightVector.Y > 0 then angle = -angle end
return angle
end
You would need to send the CFrame of the aircraft to the GetRollAngle function and you will also probably need to convert to degrees. Otherwise yes, just put it in a loop. I actually recommend using RenderStepped for this in a LocalScript.
local function GetRollAngle(orientation:CFrame)
local target:Vector3 = orientation.ZVector:Cross(Vector3.yAxis)
local angle:number = math.pi-math.acos(target:Dot(orientation.XVector))
if orientation.RightVector.Y > 0 then angle = -angle end
return angle
end
local Display = script.Parent
local block = workspace.Sensor
local run = game:GetService("RunService")
run.RenderStepped:Connect(function()
Display.P.Rotation = GetRollAngle(block.CFrame)
end)
You need to convert to degrees if I’m not mistaken. Display.P.Rotation = math.deg(GetRollAngle(block.CFrame))
Also make sure the Z side of the block is forwards and the X side points towards a wing.
If that doesn’t work, go ahead and print the angle to see where the problem is. I’ll be away for close to 20 hours, hopefully you can make some progress without me for a bit. Good luck!
Alright I am gonna give that a try, hopefully I should be able to replicate it, I may add it has to run on a server side. (It doesn’t work in client, works on the server).