- Home /
altimeter gauge...
i have been trying to find info on how create an altimeter gauge for my flight sim. Can anyone steer me in the right direction? thanks!
Answer by Novodantis 1 · Oct 30, 2010 at 10:43 PM
Depends on the level of realism in your sim. A real altimeter is just a barometer, calibrated to some pressure level datum given some assumptions (otherwise known as International Standard Atmosphere, or ISA conditions). The change in air pressure results in some interesting calculations to alter indicated altitude.
Of course if you are talking about a standard combat flying game, you're basically going to just be displaying the plane's global y coordinate (assuming y=0 to be sea level). Methods of doing this vary. Outputting the number to screen, the simplest of all, is easy. Add this script to the object:
function OnGUI() {
GUI.Label(Rect(10,10,200,20), "Altitude: "+transform.position.y);
}
That's the value you want, but I'd imagine you want to pretty it up. I'm guessing you're intending to go for the classic circular dial, which involves simply converting a numerical value to a radial one. Check out this thread on making a speedometer, the principle is essentially the same: http://answers.unity3d.com/questions/8120/how-can-i-make-an-on-screen-speedometer
Oh, in Unity's default scale that's in meters. You can display the number in feet by multiplying it by 3.281.
to trouble you once more :) how could this be modified to make a sound (alarm) when height goes under a certain number? kind of like a real plane alerts you when drop altitude?
You would simply need to check when that y coord drops below a certain number, and if so to enable a looping alarm sound. You will also want a boolean to keep track of the fact the alarm is already on, so you aren't starting the alarm sound every frame or such. Eg: var alarmSounding : boolean = false; Then your condition would be something like: if (yCoord < dangerZone && !alarmsounding) {....
Just be sure to set alarmSounding to true when you activate it, and keep the reference to the sound so you can turn it off with a similar, reverse condition
Your answer
Follow this Question
Related Questions
How to change time Splash Screen is Displayed 3 Answers
iPhone GUI Text asks for edit on touch 0 Answers
Button does not work when another is active? iPhone 5 Answers
PlayerPrefs aren't working in iphone 2 Answers