HP damage multiplies- why? Please review this project file.

Hi, all,

I have a project file attached that is problematic. The problem I am experiencing here is an exponential increase in HP damage via a script attached to a replacement object. It seems that the more objects that are instantiated, an inordinate amount of HP is subtracted. The project is fairly simple and I would appreciate any and all feedback.

Thanks,

Greg

172427–6195–$example_project_158.unitypackage (486 KB)

Anyone have any thoughts about the above?

Still looking for an answer to this one…

From what I can tell, you are way out of my league, but I am still happy to try to help - the only problem is that the download link does not work…

I try “download linked file”, which downloads “download.php”, which is shortly replaced by “example_project_158.unitypackage.gz”. Afterwards, I double click the file, and stuffit expander decompresses the .gz file, but then moves on to decompress the .unitypackadge file! This leaves me with a strange folder system.

Do you mind putting the .unitypackadge file in it’s own folder, and then uploading the folder it’s in, not just the plain .unity3packdge file? (please excuse the redundancy)

Thanks!

Hi, Flynn,

Not sure why that happened. Are you opening this in Unity Iphone by the way? I placed the project file within another folder per your request, hope that works.

Thanks,

Greg

174938–6270–$unityproject_example_169.zip (487 KB)

No, sadly I don’t have the Unity iphone extension… I will still (foolishly) try though, I am a bit bored anyways lol.

Edit:

Oh brother… On contact with using the .unitypackadge file, the log went ballistic…

It’s mostly warnings, there are only five errors, but I am worried that if I were to try and change the code, I would end up ruining it’s use…

As I said, I will still (foolishly) try…

Edit 2:

Yeah, way out of my league there, I don’t really think I can fix it, if I don’t even understand what’s going on…

I am sorry I could not help… :? Thanks for going to the trouble of fixing that download though!

   var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);
   
   for (var hit in colliders) {
      
   ...
         hit.rigidbody.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);

         break;
      }}}

The problem is that you get ALL the colliders, and then cycle through each one. Each one of them doing damage to the sun.

I don’t think that’s what you wanted, but I’m unsure of exactly what you do want.

What I did was I added a break at the end of the for loop, which makes the damage only apply once.

Ade, Tempest, Flynn,
Thanks for coming to my rescue- placing a break in the code worked perfectly! I appreciate your time and attention on this!

Hope I can return the favor,

Best,

Greg

Hi, guys,

I have another question regarding a script to make an object a child of another object. The following script subtracts hitpoints, fades up the material and
lastly, destroys the object and instantiates a dead replacement. The problem is that the object does not become a child of the parent object.

I would like to use these two scripts together to effectively make the object a child of another object.

var deadReplacement : Rigidbody;
var deadReplacementPosition : Vector3;
var deadReplacementRotation : Quaternion;
var dieSound : AudioClip;
var explosion : Transform;
var damagesound : AudioClip;
var initialDelay = 0.0;
var fadeSpeed = 1.0;
var explosionRadius = 5.0;
var explosionPower = 0.0;
var explosionDamage = 25.0;
var explosionTime = 1.0;
var myTransform : Transform;
var hit : RaycastHit;

function Start () {
   var explosionPosition = transform.position;
   var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);
   for (var hit in colliders) {
      if (!hit)
         continue;
      Debug.Log( " hit.collider.tag = " + hit.collider.tag);
      if (hit.rigidbody  hit.collider.tag == ("Respawn") ) {
         Debug.Log(" respawn object hit");
         var closestPoint = hit.ClosestPointOnBounds(explosionPosition);
         var distance = Vector3.Distance(closestPoint, explosionPosition);
         var hitPoints = 1.0;
         hitPoints *= explosionDamage;
         hit.rigidbody.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
 
         break;
      }
   }
}

renderer.material.color.a = 0.0;

yield new WaitForSeconds(initialDelay);


while (renderer.material.color.a < 1.0) {
   color = renderer.material.color;
   color.a = 1.0;
   renderer.material.color = Color.Lerp(renderer.material.color, color, fadeSpeed * Time.deltaTime);
   yield;
}

  Destroy(gameObject );
 


                                         // so this is the object touched in the 2d space
                     deadReplacementPosition = hit.transform.position;
                     deadReplacementRotation = hit.transform.rotation;
                       
                     // Play a dying audio clip
                     if (dieSound) {
                        AudioSource.PlayClipAtPoint(dieSound, transform.position);
                     }
                     // Replace ourselves with a deadbody
                     if (deadReplacement) {
                        var dead : GameObject = Instantiate(deadReplacement, deadReplacementPosition, deadReplacementRotation);
                                            }

This is the code that I’m trying to implement:

   if ( myTransform.position.x == hitTransform.position.x) {       // matches x position
                  if ( myTransform.position.y == hitTransform.position.y) {   // matches y position
                     // so this is the object touched in the 2d space
                     deadReplacementPosition = hit.transform.position;
                     deadReplacementRotation = hit.transform.rotation;
                     var parentTransform : Transform = hit.transform.parent.gameObject.transform;
                     Destroy( hit.collider.gameObject );
                     // Play a dying audio clip
                     if (dieSound) {
                        AudioSource.PlayClipAtPoint(dieSound, transform.position);
                     }
                     // Replace ourselves with a deadbody
                     if (deadReplacement) {
                        var dead : GameObject = Instantiate(deadReplacement, deadReplacementPosition, deadReplacementRotation);
                        dead.transform.parent = parentTransform;
                     }
                  }
               }
            }