x


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.

more ▼

asked Jun 03 '11 at 12:30 PM

Shrimpy gravatar image

Shrimpy
16 4 5 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Jun 03 '11 at 01:25 PM

homeros gravatar image

homeros
321 1 2 6

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jun 03 '11 at 01:02 PM

RoflHarris gravatar image

RoflHarris
971 5 8 13

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5274
x3815
x394
x254
x70

asked: Jun 03 '11 at 12:30 PM

Seen: 1029 times

Last Updated: Jun 03 '11 at 01:25 PM