Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ashtear · Jun 03, 2011 at 04:16 PM · collisionrigidbodyaddexplosionforce

AddExplosionForce only pushing objects in +Y

Hello. I'm having a problem with Rigidbody.AddExplosionForce where it seems to work as far as force and radius, but it only seems to push objects in the +Y axis.

I'm working on a space shooter game, where whenever a bullet hits a ship, the bullet prefab is destroyed and a new explosion prefab is created. The explosion prefab has a particle effect and a script that uses AddExplosionForce to push away all other rigidbodies in range.

And effectively it pushes them, but not away from the impact point, only upwards. The code is the exact example used on the Unity Script Documentation for the method, yet it only pushes others in +Y.

The game is meant as 2D, so objects only move in X and Y. Yet I'm not artificially fixing the Z velocity to 0, only being careful never to increase force in that direction. I set constraints on the rigidbody, but I don't know if either of these is part of the problem.

Any ideas? Thanks for any help.

Comment
Add comment
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

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Chris D · Jun 03, 2011 at 04:50 PM

I'd check the upwards modifier. For reference, the script is below:

 var radius = 5.0;
 var power = 10.0;
 function Start () {
      // Applies an explosion force to all nearby rigidbodies
      var explosionPos : Vector3 = transform.position;
      var colliders : Collider[] = Physics.OverlapSphere (explosionPos, radius);
 
      for (var hit : Collider in colliders) {
           if (!hit)
           continue;
 
           if (hit.rigidbody)
           hit.rigidbody.AddExplosionForce(power, explosionPos, radius, 3.0);
      }
 }

In the example, there's an upwards modifier of 3 (the last argument). Try reducing that to 0 and see what happens.

Comment
Add comment · Show 2 · 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 Ashtear · Jun 03, 2011 at 04:54 PM 0
Share

I already checked that, I reduced it to 0. Still the same behavior.

avatar image Chris D · Jun 03, 2011 at 05:19 PM 0
Share

Hmm...you know, I've had similar issues in the past but can't recall the exact fix (thought it was that...).

You're not alone having this quirk: http://forum.unity3d.com/threads/49816-AddExplosionForce-Issue?highlight=addexplosionforce

avatar image
0

Answer by benni05 · May 29, 2013 at 01:16 PM

In my case the issue was that the distance between the center of the explosion and the radius of the collider of the rigidbody the explosion force was applied to was too small, letting the explosion happen INSIDE the collider. This had the effect of the rigibody always thrown in Y direction.

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 BloodOmen · Mar 28, 2014 at 04:29 AM

So, Unity actually force an upward value only for direction in AddExplosionForce. It become the most apparent at the contact point very close to the explosion position. Also, if you set a value of 0.0f as Upward, Unity will actually change it as 1.0f for you. It's nice like that.

Personally, I find it good enough for pushing the body away from the explosion. I have upward value as 0.01f.

But I have a case where my radius is 0.0f, then I do a special case, which you could do yourself otherwise sadly.

I have a physic utility function where I do this

 [Missing code here]
 // F = m * a
 // The velocity here of the rigid body is consider to instantly decrease to 0 by touching a collision
 // Therefore we transform the velocity into acceleration (being a deceleration)
 float explosionForce = rigidBodyExplosionFrom.velocity.magnitude * rigidBodyExplosionFrom.mass;
 if (radius == 0.0f)
 {
     targetRigidBody.AddForceAtPosition(rigidBodyExplosionFrom.velocity.normalized * explosionForce, explosionPosition, forceMode);
 }
 else
 {
     targetRigidBody.AddExplosionForce(explosionForce, explosionPosition, radius, upwardModifier, forceMode);
 }

Since it's an explosion I use ForceMode.Impulse

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 ss_kemper0k · Sep 29, 2020 at 10:58 AM

I had almost the same problem, AddForceAtPosition moved my player prefab only by Y-axis. I disabled "Apply root motion" flag in Animator component, and it solves my problem.

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 Will_at_BridgeWorxGames · Nov 04, 2020 at 05:04 PM

I had the same problem. When I added a forcemode, it did the trick!

 Collider[] colliders = Physics.OverlapSphere(this.transform.position, checkRadius);
 foreach (Collider myhit in colliders) {
     Rigidbody rb = myhit.GetComponent<Rigidbody>();
     if (rb != null) {
         rb.WakeUp();
         rb.isKinematic = false;
         rb.velocity = Vector3.zero;  //This makes physics force consistent
         rb.AddExplosionForce(blastPower, this.transform.position, blastRadius, upForce, ForceMode.Force);
         Debug.Log("KABOOM! KABOOM!");
 }

}

I chose ridiculous values initially that I set in the inspector, and they were:

blastPower = 10000, blastRadius = 100, upForce = 0

For more information on the differences between the forcemodes, I found this thread to be helpful! https://answers.unity.com/questions/696068/difference-between-forcemodeforceaccelerationimpul.html?childToView=1740080#comment-1740080

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

7 People are following this question.

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

Related Questions

What does rigidbodies sleeping have to do with collision detection? 0 Answers

Apply explosive force to player at point of contact 3 Answers

ExplosionForce On Instantiated Object 1 Answer

Why does my player fly through my barrier? 2 Answers

Advice for Intersecting Colliders 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