How could a damage meter be made like the Super Smash?
Could you provide a bit more detail about what aspect of the Super Smash damage meter you need help with?
In a broad sense, you will want to assign each character a damage
variable that tracks how much damage they’ve taken, and then have a helper function that converts that damage into a damageFactor
which determines how much it will affect the character’s knockback. For example, it could look something like this (note: I don’t have Unity in front of me so consider this to be somewhat pseudocode):
private float damage;
// First, we calculate the damage factor based on the current damage. In this example,
// I divide by 10, but your actual calculation might be a lot more complicated. I would
// recommend assigning public variables to the different values in your function so
// you can easily test how it plays with different values.
private float getDamageFactor() {
return this.damage / 10;
}
// Here, we fetch the mass of the rigidbody and multiply it by the damageFactor. This is
// assuming that mass is what is used to distinguish a heavy character (like Bowser) from
// a lighter character (like Sheik)
private float getKnockback() {
rb = GetComponent<Rigidbody>();
float damageFactor = this.getDamageFactor();
return rb.mass * damageFactor;
}
You could then multiply the result of getKnockback()
by the normal velocity change of a hit in order to make a character go flying more or less depending on how much damage they have taken.