Help with buoyancy physics calculation

Hello! I am trying to figure out how to take a buoyancy and mass, and then shrink it down into a range between minHeight and maxHeight. Depending on the ratio of mass to buoyancy, the value returned would be lower or higher, with both values being equal to each other putting the value to be in the middle of the two heights.

function calcHeight()
	local correctHeight = (math.tanh(buoyancy/mass) * ((maxHeight - minHeight) / 2)) + ((maxHeight  - minHeight) / 2)
	print(correctHeight)
	return correctHeight
end

This is the closest I’ve gotten to getting it right, but it still doesn’t function much how I wanted it to, and I’m not sure what to do next. Any help is appreciated!

image

I finally got something to work how I wanted to, after scrolling on math forums and googling random terms that were similar to what I wanted, I finally found the sigmoid function, so I combined it with what I had and figured out how to map the range I got it to give (0-1) to the range (d-u)
m is Mass, b is Buoyancy, u is MaxHeight and d is MinHeight. I still need to convert this to Lua code, but hopefully this helps whoever comes across this

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.