Can some one help me to make an Altimeter?
textmeshproUGUI to display altitude of my airplane.
Do you have a specific question / problem?
You have the Y position of your plane. If you want it relative to the ground, cast a ray downwards. Then display this number however you want. Im not very familiar with Altimeters, but if i remember correctly, you have pointers like on a watch, one for kilometers one for hundred meters or so.
So you need to split your number into two values. For a number like 3500, wed want to get a 3 and a 500. To do that simply divide by 1000 and round down to get 3, and calculate modulo 1000 to get the 500.
Now you need a way to display these numbers on your Altimeter. For that you could scale the value to x/360 and use that number in degrees to rotate the pointer to the correct place. So for example, if the large pointer is scaled between 0 and 10, then 3 would be 3/10*360 = 108° rotated.
Put some GUI in the background and that should be more or less it.
thanks
Just what Yoreki said… this was my implementation:
float altitude = ... however you obtain it here ...
altitude = -altitude;
var rot1 = (360 * altitude) / 1000;
var rot2 = (360 * altitude) / 100;
Needle1.localRotation = Quaternion.Euler( 0, 0, rot1);
Needle2.localRotation = Quaternion.Euler( 0, 0, rot2);
The Needle1/Needle2 properties are RectTransforms (or Transforms if you prefer) of the two needles.
My quick googlefu says altimeters typically work off of air pressure, and measure altitude above sea level. So I think using world space Y position would be better than raycast to ground level. Convenient it is also easier
They do indeed… and the published info for an airport gives field elevation so you can calculate where to show up for the pattern.
But radar altimeters behave the way a raycast to ground would behave, like the one in Jetpack Kurt:
https://www.youtube.com/watch?v=6-On25gkWe8
Just a series of raycasts in a 1-unit ring around the base of your ship, and if you are over uneven ground (any one raycast is more than half a world unit than the other), it illuminates the uneven terrain indicator and beeps.
Yeah he said “airplane” though in the OP
Though I wonder what value an air pressure altimeter would say in the vacuum of space?
That kind of questions is what the internet is made for, I suspect it will attempt to reach infinity but will break on the way depending on the maker, this one breaks at 50,000 ft / 15 KM
https://www.youtube.com/ watch?v=fmV9fQseRwE
I would laugh pretty hard if it just said “NaN”
In space, no-one can hear you NaN.
But in space, you also can divide by zero.