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 cregox · Jan 31, 2011 at 07:20 PM · physicsexplosionwind

Modify AddExplosionForce and allow upwardsModifier to any direction instead

Is there any easy way to implement this or do we need to do it manually? Anyone happen to already know of some good implementation of this?

I want something like to this:

function AddExplosionForceModifier (explosionForce : float, explosionPosition : Vector3, explosionRadius : float, explosionOriginPoint : Vector3 = new Vector3(0.0F,0.0F,0.0F), mode : ForceMode = ForceMode.Force) : void

So I can point the explosionOriginPoint (rather than a directionModifier or upwardsModifier) to anywhere and not just up or down.

I'm using AddExplosionForce for wind emulation, and it works great to go up. But now I need new directions.

edit: I just noted this question could also be asked in another way which will hopefully facilitate me finding the answer on my own:

How is the code implementation on AddExplosionForce?

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

3 Replies

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

Answer by cregox · Feb 01, 2011 at 12:15 AM

Here, I just implemented it myself... Tho it's still far from perfect, it simulates the behavior I need for this moment.

Just create a RigidbodyExtensions.cs anywhere inside the unity project and add this:

using UnityEngine; using System.Collections;

public static class RigidbodyExtensions : object { public static void AddExplosionForce (this Rigidbody body, float explosionForce, Vector3 explosionRadiusCenter, float explosionRadius) { AddExplosionForce(body, explosionForce, explosionRadiusCenter, explosionRadius, new Vector3(0F, 0F, 0F)); } public static void AddExplosionForce (this Rigidbody body, float explosionForce, Vector3 explosionRadiusCenter, float explosionRadius, Vector3 explosionOriginPoint) { AddExplosionForce(body, explosionForce, explosionRadiusCenter, explosionRadius, explosionOriginPoint, ForceMode.Force); } public static void AddExplosionForce ( // still missing torque - try using "AddForceAtPosition" later on this Rigidbody body , float explosionForce , Vector3 explosionRadiusCenter , float explosionRadius , Vector3 explosionOriginPoint // this is the oposite from upwardsModifier , ForceMode mode ) { if (Vector3.Distance(body.transform.position, explosionRadiusCenter) <= explosionRadius) { Vector3 force = (body.transform.position - (explosionRadiusCenter + explosionOriginPoint)); body.AddForce(force * (explosionForce/5), mode); // 5 came from experimentation } } }

here's a comparison usage:

rigidbody.AddExplosionForce(2000F, transform.position, 2F, 3f); // unity's

rigidbody.AddExplosionForce(2000F, transform.position, 2F, -(new Vector3(0F, 3F, 0F))); // cawas

note the **-** sign. it's needed for similar behavior.

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 3DMagicVR · Jan 31, 2011 at 07:39 PM

I think you must play around with the explosionPosition and with the explosionOriginPoint if it's part of the function, because if it's not I don't think that works.

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 cregox · Jan 31, 2011 at 07:57 PM 0
Share

I think you missed my point. The function doesn't have it as Vector3, it's a float point. Take a look at it. ;)

avatar image
0

Answer by Goody! · Jan 31, 2011 at 07:48 PM

Do a search for add.force and constant.force. I believe you can specify direction with those. You can also set them to be local to the object of local to the world.

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 cregox · Jan 31, 2011 at 07:59 PM 0
Share

The major point of explosionforce is that it's applied as the name imply - an explosion. If the object is 3 feets away but within the explosion radius it will be less affected than an object in the center of the explosion.

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

No one has followed this question yet.

Related Questions

Move rigid body using explosion force in C# 0 Answers

2D 360 degress platformer example needed 0 Answers

How to I calculate damage when using AddExplosionForce? 0 Answers

How do I import a wall of bricks with Individual Bricks responding to Physics in Unity? 0 Answers

How would you create wind within unity? 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