Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by Josh 11 · Dec 03, 2010 at 10:15 PM · damageexplosionfpstutorial

FPS Tutorial Rocket Launcher

I have just finished the FPSTutorial, I realized it has been removed from the tutorial section, but it still had a lot of good information. Everything works great except my rocket launcher explosions don't do damage to the robot or the player. They damage the barrels just fine. The machine gun does damage to the robot and the player and the barrels. It's just the explosion on the rocket launcher that doesn't do damage.

I have the CharacterDamage script attatched to the robot:

var hitPoints = 100.0; var deadReplacement : Transform; var dieSound : AudioClip;

function ApplyDamage (damage : float) { // We already have less than 0 hitpoints, maybe we got killed already? if (hitPoints <= 0.0) return;

 hitPoints -= damage;
 if (hitPoints &lt;= 0.0)
 {
     Detonate();
 }

}

function Detonate () { // Destroy ourselves Destroy(gameObject);

 // Play a dying audio clip
 if (dieSound)
     AudioSource.PlayClipAtPoint(dieSound, transform.position);

 // Replace ourselves with the dead body
 if (deadReplacement) {
     var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);

     // Copy position &amp; rotation from the old hierarchy into the dead replacement
     CopyTransformsRecurse(transform, dead);
 }

}

static function CopyTransformsRecurse (src : Transform, dst : Transform) { dst.position = src.position; dst.rotation = src.rotation;

 for (var child : Transform in dst) {
     // Match the transform with the same name
     var curSrc = src.Find(child.name);
     if (curSrc)
         CopyTransformsRecurse(curSrc, child);
 }

}

Here is the Explosion script attatched to the rocket:

var explosionRadius = 5.0; var explosionPower = 10.0; var explosionDamage = 100.0;

var explosionTime = 1.0;

var raycastRange = 1.0;

function Start () {

 var explosionPosition = transform.position;
 var colliders : Collider[] = Physics.OverlapSphere (explosionPosition, explosionRadius);

 for (var hit in colliders) {
     if (!hit){
         continue;
         }

     if (hit.rigidbody) {
     Debug.Log("hit");
         hit.rigidbody.AddExplosionForce(explosionPower, explosionPosition, explosionRadius, 3.0);

         var closestPoint = hit.rigidbody.ClosestPointOnBounds(explosionPosition);
         var distance = Vector3.Distance(closestPoint, explosionPosition);

         // The hit points we apply fall decrease with distance from the hit point
         var hitPoints = 1.0 - Mathf.Clamp01(distance / explosionRadius);
         hitPoints *= explosionDamage;

         // Tell the rigidbody or any other script attached to the hit object 
         // how much damage is to be applied!
         hit.rigidbody.SendMessageUpwards("ApplyDamage", hitPoints, SendMessageOptions.DontRequireReceiver);
     }
 }

 var direction = transform.TransformDirection(Vector3.forward);
 var hit : RaycastHit;

 // Did we hit anything?
 if (Physics.Raycast (transform.position, direction, hit, raycastRange)) {
     if (hit.rigidbody)      
         hit.collider.SendMessageUpwards("ApplyDamage", explosionDamage, SendMessageOptions.DontRequireReceiver);
 }

 // stop emitting ?
 if (particleEmitter) {
     particleEmitter.emit = true;
     yield WaitForSeconds(0.5);
     particleEmitter.emit = false;
 }

 // destroy the explosion
 Destroy (gameObject, explosionTime);

}

Like I said everything works great except for the explosions damaging the robot/player. Any help would be appreciated.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eeveelution8 · Mar 13, 2013 at 12:10 AM 0
Share

it works for me just fine :I

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by networkZombie · Jan 17, 2011 at 04:21 AM

i have the same problem. could you PM me the solution if you have it?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image daymont87 · Mar 13, 2013 at 05:16 AM 0
Share

Look up - $$anonymous$$nightChatX post)

To fix this problem you need to change the Explosion-Simple for the Small explosion Prefab to Explosion-Advanced script.

avatar image
0

Answer by PunsAndAmmo · Jan 17, 2011 at 06:13 AM

The problem is that neither the robot or the character in the tutorial have a rigidbody attached, and the script is only checking for rigidbodies to apply the damage to.

Replace rigidbody with collider wherever it occurs in that script and it should work fine (I haven't tested that one in particular but that is why it doesn't work right).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by KnightChatX · Apr 21, 2011 at 10:44 AM

Ok, the problem here is the Explosion-Simple script is being used instead of the Explosion-Advanced script.

To fix this problem you need to change the Explosion-Simple for the Small explosion Prefab to Explosion-Advanced script.

And you can add these settings to the Explosion-Advanced script:

Explosion Radius = 6

Explosion Power = 90

Explosion Damage = 50

Explosion Timeout = 2

That will definately fix it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by daymont87 · Dec 23, 2012 at 10:33 AM

KnightChatX, thanks!!!! i try find the solution 3 days!!!! And now I use Explosion-Advanced script instead Explosion-Simple and it works!!! Yuhuhuhuhhh!!)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

2D Explosion Damage Calculation - 2DCollider Bound 3 Answers

Damage Reciever Won't Destroy Object 1 Answer

Damage sending with grenades. 1 Answer

how to apply damage to enemy when it collides with particle 1 Answer

Restricting horizontal slash attack 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges