# Atmosphere Meter

I’m trying to make an atmosphere meter like the one in plane crazy, aswell as the one in kerbal space program. I got a value of the height which the formula used is this.

``````while wait() do
script.Parent.Height.Value = (hrp.Position - Baseplate.Position).Magnitude
end
``````

It basically calculates the position of the humanoidrootpart, subtracting it by the baseplates positions magnitude. Which changes the height value to that.

So, by atmosphere meter, it will basically have a white line at the bottom, which is the starting point. I want it to go up and show you where you are in the atmosphere. I’m sorry if I sound greedy for a script or anything, just don’t know how I’d do this. Thanks in advance - if you want me to elaborate please tell me and ill just do that for you. Cheers!

1 Like

So what you will want to do is have a minimum height value, ground zero, and a maximum value, say, space.

You can represent these two values with two ends of a frame, or, your atmosphere meter’s frame.

By checking the height value of the player and comparing it with ground zero and space, you can get the ratio of the player’s distance from each.

For example, if ground zero is 0 studs, and space is 6000 studs, and your character is currently at 2000 studs, that means that your ratio is 2000/6000, or 1/3.

Now that you have your ratio, you can use it in your altimeter. Devide the size of the meter frame by the ratio of 1/3. The result is the size of the actual meter UI object.

You can then change the meter UI object’s size to the size value we just solved for. Now, simply move it up half its vertical size from the position of the bottom of the meter’s frame, and viola.

I would recommend using run service’s Heartbeat for this, as opposed to a while loop.

2 Likes

So, I’ve got the maxium height, minimum and the ground value. I’ll be sure to try this.

This really isn’t going to give you the height as the x and y-coordinates are taken into account - only the y-coordinate difference needs to be accounted for. Even when you’re underneath the baseplate, the values will be positive since it’s getting the length of the vector and it’s always positive, so your height value should look like this:

``````script.Parent.Height.Value = (hrp.Position.Y - Baseplate.Position.Y)
``````

With that out of the way, you first need to define the highest point that the player can reach, for argument’s sake, say 500 studs high. You’d need to calculate the player’s height, then divide it by the highest point (500) to get a percentage of the player’s height. From there, you can apply it to your “atmosphere meter” gui:

``````local per = (hrp.Position.Y - Baseplate.Position.Y) / 500
atmosMeter.WhiteBar.Position = UDim2.new(0, 0, math.clamp(per, 0, 1), 0)
``````
1 Like

Ill try this out, also by atmosphere meter is the level of atmosphere. sorry if i got you confused.

It works, but its at the top of the image label how can I reverse this?

Try this:

``````atmosMeter.WhiteBar.Position = UDim2.new(0, 0, math.clamp(1 - per, 0, 1), 0)
``````
1 Like

Okies, will do. I’m probably gonna see what math.clamp does in the future aswell.

It works, thank you so much man.

`math.clamp(x, a, b)` essentially makes `x` be between the range of `a - b`, meaning if `x < a`, the function will return `a`, if `x > b`, then the function will return `b`, and if `a < x < b` (x is greater than a, but less than b), then the function will return `x`

1 Like

What a handful, will try to learn this furthermore. Your help was very much appreciated. Thank you.