So I’m part of making a basic 2D platformer where you advance upwards & I need there to be a HUD that shows player altitude, perhaps in ft & km as a sign of player progress.
Idk if I’m programming an altimeter or what, but since the game is 2D, there’s really no need pointing anything as rotation pointers.
Just 2D values going up. So I guess there needs to be raycast pointing on Y axis at the very least. And some way for game to set height units and add them as the player goes up.
It’s worth noting what altitude actually is in order to understand the maths behind it but you’re already halfway there knowing that you can use a raycast. In this case you would measure with a raycast the distance from the player to the ground and that will give you the correct end result but unity has a feature for this called vector3.distance as well.
Above states that altitude is distance above sea level - did you want it above ground level (unfixed) or a fixed level (ie the sea). You could simply refer to your object’s Y coordinate in 2D?
Yes, I was just looking at it for general reference, in the OP’s case it doesn’t necessarily need to be explicit unless they want to get really anal about the maths. When it comes to games and the like of course if you’re not going to be realistic about it sea level could be entirely made up anyway.
What you describe is just a vertical distance measure, not really an altimeter (or radar altimeter) in the general sense.
All you need is to copy the transform.position.y value out and use that (perhaps after subtracting the initial .y value you start at, if it is not zero) for your score.
You do not care about raycast if you don’t care how far a varying ground is below you.