Fall Damage

What is the best way to find fall damage? I have an idea that I wrote, but I’m not sure if it’s the best way. Any guidance?

var v = rigidbody.velocity.y;
	var d = 1;
	speed = v;
	
	if(grounded == true)
	{
		speed = 0;
		
		if(v < -1.0)
		{
			health += v;
		}
	}

Something like this? It works in all directions but you could easily reduce it just to the Y axis.

    public Vector3 Velocity;
    public Rigidbody RidgedBody;
    public bool IsAlive = true;
    private double _decelerationTolerance = 12.0;

    void Start() 
    {
        RidgedBody = GetComponent<Rigidbody>();
    }
    void FixedUpdate() 
    {
        if(IsAlive)
        {
            IsAlive = Vector3.Distance(RidgedBody.velocity, Velocity) < _decelerationTolerance;
            Velocity = RidgedBody.velocity;
        }
    }

For character controller I would use a variable that calculates the air time and then take from the player’s health when touching the ground:

var minSurviveFall : float = 2f; //the time that the player can spend in the air without taking damage
var damageForSeconds : float = 1f; //damage taken for 1 second in air (for airTime = 1)
private var _controller : CharacterController;
private var airTime : float = 0;

var playerHealth : float = 10; //you can use your own variable here, or make a reference to a variable in other script

function Start () {
_controller = GetComponent(CharacterController);
}

function Update() {
if(!_controller .isGrounded)
{
airTime += Time.deltaTime;
}
if(_controller .isGrounded)
{
if(airTime > minSurviveFall)
{
playerHealth -= damageForSeconds * airTime;
}
airTime = 0;
}
}

It is checked for errors, but it’s not playtested

Hi I know this is an old post but incase someone new comes along like I did I have posted a video with a project download link to a heavily extended first person controller