x


How is calculate this?

Hello I need to understand how this is calculate,I have a DamageSystem.js for all type of damage, with inside

  var HEALT = 100;
.....
function FallDamage(Damage :float ){

    HEALT -= Damage;

   HEALT --;
     Debug.Log("I'm falling");
 }

and a send message on FPS Walker

  function FallingDamageAlert (fallDistance : float) {
      FindObjectsOfType(Damage_System);
         if (fallDistance >= 15)
          {
            gameObject.SendMessageUpwards ("FallDamage",4,SendMessageOptions.DontRequireReceiver);
          }

        if (fallDistance >= 20)
         { 
           gameObject.SendMessageUpwards ("FallDamage",19,SendMessageOptions.DontRequireReceiver);
         }
     Debug.Log ("Ouch! Fell " + fallDistance + " units!");  
 }

My questions is, I want remove 5 for fallDistance >= 15 + 20 for fallDistance >= 20, in total 25, but need write 4 and 19.

Why will be removed 5 health point for if (fallDistance >= 15), and 20 for if (fallDistance >= 20), if I write 4 and 19

hope is understandable and do not did a mess

more ▼

asked Aug 11 '12 at 10:20 AM

Ingen gravatar image

Ingen
145 3 11 19

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

2 answers: sort voted first
HEALT -= Damage; // is the same as HEALT = HEALT - Damage;
HEALT --;        // is the same as HEALT = HEALT -1;

You first subtract the actual damgage from your health then you subtract additional 1.

more ▼

answered Aug 11 '12 at 10:55 AM

zyzyx gravatar image

zyzyx
226 1 3

thanks a lot

Aug 11 '12 at 11:12 AM Ingen
(comments are locked)
10|3000 characters needed characters left

As @zyzyx said, you're actually applying Damage+1. You could make your code more clear by just subtracting Damage from HEALT, and improve the messaging by using a single SendMessageUpwards (SendMessage functions are a bit slow):

function FallDamage(Damage :float ){
  HEALT -= Damage;
  Debug.Log("I'm falling");
}

// send message:
  ...
  function FallingDamageAlert (fallDistance : float) {
    ...
    if (fallDistance >= 15){   // if fallDistance >= 15...
      var damage: float = 5;   //  assume damage 5... 
      if (fallDistance >= 20){ //  but if it's >= 20...
        damage = 25;           //  change damage to 25
      }                        // apply the specified damage
      gameObject.SendMessageUpwards ("FallDamage", damage, SendMessageOptions.DontRequireReceiver);
      Debug.Log ("Ouch! Fell " + fallDistance + " units!");  
    }
  }

more ▼

answered Aug 11 '12 at 11:13 AM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

thank you very much Aldo,

I tried to do this but without find the right way, I need too much learn

thank you again

Aug 11 '12 at 11:38 AM Ingen
(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:

x1

asked: Aug 11 '12 at 10:20 AM

Seen: 158 times

Last Updated: Aug 11 '12 at 11:38 AM