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
0
Question by Scacchi · Feb 15, 2013 at 07:46 AM · damagegrenade

Make grenade doesnt affect anything if it is behind wall

Hello guys, its my first post here, hope you can help me... I have a grenade object, that destroys itself in a certain time, and I have THIS FUNCTION CALLED IN OnDestroy() :

 function AreaDamageEnemies(location : Vector3, radius : float , damage : float ) {
     var objectsInRange : Collider[] = Physics.OverlapSphere(location, radius);
     for (var hit : Collider in objectsInRange) {
         if (!hit) {
             continue;
         }
 
         var proximity : float = (location - hit.transform.position).magnitude;
         var effect : float = 1 - (proximity / radius);
         
         if (hit.tag == "Movible") {
                     hit.rigidbody.AddExplosionForce(50, this.transform.position, 10, 3.0);
         }
             
         if(hit.tag == "Blanco") {
             var VidaNegra : ManejadordeBlancos = hit.GetComponent(ManejadordeBlancos);
             var IA : InteligenciaArtificialNegra1 = hit.GetComponent(InteligenciaArtificialNegra1);
             var NuevoVector : Vector3 = hit.transform.position - this.transform.position;
             VidaNegra.DecrementaSalud(damage * effect);
             IA.ExplosionGranada(NuevoVector);
         }
         
         if(hit.tag == "Vidrio") {
             hit.GetComponent("VidaVidrios").VidaVidrio = 0;
         }
         
         if(hit.tag == "Player") {
             var Vida : playerStatus = hit.GetComponent(playerStatus);
             var varx = ((damage * effect) - 20);
             if(varx > 0)
                 Vida.aplicarDamage(varx);
         }
     }
 }

You dont have to fully understand what I do to every single tag, I talk spanish and program in spanish, so you wont understand most names, I just wants those "if´s" to be executed if its not a wall in the way... I tried all the ways, I searched "Grenade damage" to page 5 of the forums but nothing will work, It must be me who is doing it wrong, can anybody help me?

Comment
Add comment · Show 8
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 Kirlim · Feb 15, 2013 at 10:42 AM 0
Share

Have you tried using a raycast that starts in the grenade position and end in the tagged object (player, blanco, etc)? http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

avatar image Vandaxian · Feb 15, 2013 at 10:57 AM 0
Share

Is it possible that the wall is also a rigidbody, and the explosion is only absorbed by the wall, without spash damage affecting other objects within the radius?

avatar image Scacchi · Feb 15, 2013 at 08:19 PM 0
Share

Sorry if it sounds quite noob but I just cant get the raycast done, I mean, from all the versions of the Raycast function they ask an Origin, and a direction, What is the way to represent that "Direction" in to the position of the enemy? I think thats where my error is but I cant get it right! Can you tell me what the parametres of the raycast would be?

avatar image Loius · Feb 15, 2013 at 08:21 PM 0
Share

direction = targetposition - originposition

avatar image Scacchi · Feb 16, 2013 at 06:19 AM 0
Share

Ok, I added

 var COL : RaycastHit;
 if (Physics.Raycast (location, (hit.transform.position - location), COL))

At the beginning of the for (var hit : Collider in objectsInRange) and encapsuled all the "if´s" in that Raycast, and in the "if´s" checks I do, for example this:

 if(hit.tag == "Player" && COL.collider.tag == "Player")

But the surprise I got, is the grenade works only with the player, I mean, the only one who gets hurted is the player, not the enemy (Blanco) or the glasses (Vidrio) Any idea why is this?

Note: The player gets hurted only when is directly exposed to the grenade, not if there is a wall between, so basically the script works well, but only with the player... :(

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Scacchi · Feb 17, 2013 at 04:10 AM

Guys, I found the answer and it was the simpliest thing ever done, since its indeed the answer to the question Im going to post it here... Aparently when you use raycast, and you tell it to go from the position of one object (Grenade) to the position of another object (Enemy, Player, etc) the Raycast goes FROM PIVOT POINT ---> TO PIVOT POINT So my problem was this:

alt text

I had my pivot point of the object OUTSIDE of the collider, so, the raycast goes from the grenade pivot point to the enemy pivot point, did it hit anything? No, because the pivot point isnt inside the collider, so it never touched it... So I did what you see in the second example... I expanded the CharacterController (It could be any collider) so the pivot point its inside it, so the raycast will hit it. Fortunately for me, I was going to change the model of the enemy for one better shaped, so I dont really care, Im just going to make sure the pivot point of this one is in the center, or the head, so I make sure there wont be colliders errors... Hope you dont get any serious problem with this, good luck and thanks for helping!


error.jpg (206.6 kB)
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

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycast grenade? 2 Answers

C# Grenade Explosion in Radius 1 Answer

Grenade Damage in Radius 2 Answers

Deal Damage On Collision 3 Answers

[SOLVED]Different levels of damage per particle collision 1 Answer


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