Hi, I have the following code
[SerializeField] private float _Gravity = 8f;
[SerializeField] private float _JumpHeight = 2f;
[SerializeField] private float _FallDamageThreshold = 5f;
[SerializeField] private float _FallDamegeMultiplier = 2f;
[SerializeField] private float _Health = 100f;
[SerializeField] private float _MaxHealth = 100f;
private bool isDead()
{
if (_Health < 0)
{
_Health = 0;
return true;
} else
{
return false;
}
}
private void FixedUpdate()
{
if (!isDead())
{
float fall = Vector3.Distance(_CharacterController.velocity, velocity);
Debug.Log(fall);
if (fall > _FallDamageThreshold && _CharacterController.isGrounded)
{
_Damage = fall * _FallDamegeMultiplier;
_Health -= _Damage;
}
velocity = _CharacterController.velocity;
Debug.Log("HP:" + _Health + ", Damage:" + _Damage);
}
}
The code is part of the Player script that controls the player. And it’s supposed to cause some damage to the player when falling from a height greater than the height set in the _FallDamageThreshold variable, it’s not “yet” worked out. And it actually works pretty well, that is, only until the player jumps on the plane, in which case damage is taken, and quite high damage at that. Could someone help me modify the code to make it work properly?