- Home /
Health Bar Only For Falling Damage
Hi, i need help with a health bar which only takes damage if you were to fall from a certain height or higher. I am not asking anyone to write my code as i want to learn how to script myself, much like my other question "Wall Jump Help" could anyone tell me what sort of things i would need to write for this to work, thankyou.
Answer by homeros · Jun 03, 2011 at 01:25 PM
Use this to understand if the collision was from below: http://unity3d.com/support/documentation/ScriptReference/CharacterController-collisionFlags.html
And use this to understand the velocity of the collision: http://unity3d.com/support/documentation/ScriptReference/Collision-relativeVelocity.html
So use an OnCollisionEnter method and inside it, check if the character is collided from below, if it is do your damage calculations.
Answer by tnetennba · Jun 03, 2011 at 01:02 PM
You would need to keep track of the change in the objects y position between frames i.e. current and previous. Then if the change is minus, going down, then store a start position based on the previous and flag that object as falling. Now that you have the object as falling you can check for there being no difference between the current position and the previous. When there is no difference you have stopped falling and you can calculate the distance that the object has fell from the start position and base the damage from that.
Your answer
Follow this Question
Related Questions
need help with GUI healthbar 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Deduct health on collision 2 Answers
Tunnel Vision Health System 3 Answers
Inverse health bar 2 Answers