Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Brendtron5000 · Oct 31, 2013 at 07:40 PM · physicsforceexplosionaddexplosionforce

AddExplosionForce only goes up

I've got a projectile that explodes when it hits any collider. The problem is that it only seems to produce force in the +y direction. I've tried leaving out the upwardsModifier and setting it to zero. Neither helped. My code:

 Vector3 explosionPos = transform.position;
 Collider[] colliders = Physics.OverlapSphere (explosionPos, radius);
 foreach(Collider hit in colliders) 
 {
 if (!hit)
     continue;
 
 if (hit.rigidbody)
 {
     if(hit.rigidbody != this.rigidbody)
     {
         hit.rigidbody.AddExplosionForce(power, explosionPos, radius);
         Debug.Log(hit);
     }
 }
 }

I can see that it's hitting the correct collider from the debug statement.

Comment
Add comment · 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 robertbu · Nov 01, 2013 at 12:02 AM 1
Share

As a start between lines 11 and 12, insert:

 Debug.DrawRay(transform.position, hit.transform.position - transform.position, Color.red, 5.0);

The red line will display for 5.0 seconds and should be aligned with the explosion force. This will allow you to visualize your geometry to make sure it is as you expect.

avatar image Brendtron5000 · Nov 01, 2013 at 07:14 AM 0
Share

The red line is going from the point of impact to the center of the collider for the hit object. That is where I would like the explosion to force to head, but I don't think it's actually doing that. AddExplosionForce is mysterious...

avatar image robertbu · Nov 01, 2013 at 03:51 PM 0
Share

As a text, replace your AddExplosionForce() with:

 hit.rigidbody.AddForce((hit.transform.position - transform.position).normalized * 100.0f);

If this also does not work, check to see if your object is colliding with anything or if a script on the individual objects is impacting movement. For example freezing x and z movement of the rigidbody would cause this behavior.

avatar image Brendtron5000 · Nov 13, 2013 at 07:21 PM 0
Share

Yes, I am freezing movement in the z axis. I will try turning that off to see how it reacts. If freezing the z axis is causing the problem I'll have to apply forces manually.

0 Replies

· Add your reply
  • Sort: 

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

15 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

Related Questions

AddExplosionForce constantly like a fan 1 Answer

How can use AddExplosionForce to explode scattered objects? 1 Answer

Default Unity Rigidbody.AddExplosionForce script problem 1 Answer

How to I calculate damage when using AddExplosionForce? 0 Answers

AddExplosionForce 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