• 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 /
This question was closed Apr 16, 2014 at 01:49 PM by Benproductions1 for the following reason:

Other

avatar image
Question by Sveyh · Apr 16, 2014 at 09:55 AM · ragdollmove an objectexplosiongrenade

Unity3D grenade not exploding correctly

So I have my grenade script, and its working but not great. I got my ragdoll that Im testing the grenades on and that ragdoll is moving in the direction that Im throwing from, even if I throw a grenade infront of him and Im standing behind him, he is moving forward...How can I make this so he moves in the direction depending on where the bomb is?

 public class GrenadeThrow : MonoBehaviour 
 {
     public Rigidbody Grenade;
     public Transform GrenadeBarrel;
     public float timeBetweenShots = 0.03f; 
     private float timestamp;
     public int GrenadeAmmo = 5;
     public float radius = 5.0F;
     public float power = 10.0F;
     
     
     
     void Update () 
     {
         if (GrenadeAmmo > 0) 
         {
             if (Input.GetKeyDown (KeyCode.G)) 
             {
                 Rigidbody GrenadeInstance;
                 GrenadeInstance = Instantiate(Grenade, GrenadeBarrel.position, GrenadeBarrel.rotation) as Rigidbody;
                 GrenadeInstance.AddForce(GrenadeBarrel.forward * 700);
                 Invoke("Explosion", 2);
                 timestamp = Time.time + timeBetweenShots;
                 GrenadeAmmo--;
             }    
         }
     }
     public void Explosion()
     {
         Vector3 explosionPos = transform.position;
         Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);
         foreach (Collider hit in colliders) 
         {
             if (hit && hit.rigidbody)
                 hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0F);
             
         }
         
     }
 }

I have checked the Unity Script Reference, and thats where I got the "Exploding" part from. And there is one more thing, the explosion has no effect on the ragdoll if Im standing far away and the bomb lands next to him, but if I walk up with my FPS controller next to him and throw a bomb AT THE SAME PLACE, it blows the ragdoll away...

Comment

People who like this

0 Show 4
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 Benproductions1 · Apr 16, 2014 at 12:26 PM 1
Share

Not only is the explosion originating from the thrower, so is the force of it. You're throwing a grenade object, then creating an explosion at your position.

avatar image Sveyh · Apr 16, 2014 at 12:32 PM 0
Share

Okay...I'll try figure something out

avatar image Sveyh · Apr 16, 2014 at 12:37 PM 0
Share

got any tips or tricks I could use?

avatar image Benproductions1 · Apr 16, 2014 at 12:46 PM 0
Share

Try to imagine yourself as being the script. What happens and what do you do, from your perspective. That tends to work sometimes. It's quite obvious you need to either split this up into multiple scripts or use some form of collection.

1 Reply

  • Sort: 
avatar image
Best Answer

Answer by Sveyh · Apr 16, 2014 at 12:46 PM

Im so sorry for being a retard, I just added line 28 down to 35 into my "destroy" script which causes the explosion, and it works now, Im sorry lol, thanks anyways

Comment

People who like this

0 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 Benproductions1 · Apr 16, 2014 at 01:51 PM 0
Share

No harm done, glad you got it working ;)

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D explosion that targets specific gameobjects 1 Answer

How do you make a ragdoll blow apart? 1 Answer

Null reference and GetComponent 1 Answer

OverlapSphere not causing damage? - Solved 2 Answers

Raycast collider detector lags horribly? 2 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