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
3
Question by Dreeka · Aug 09, 2011 at 03:33 PM · rigidbodyforce

Add force which throws back an object

Hello,

I would like to do the following: When my marble rolls to a mine, then the mine would explode, and throw the marble back to the opposite direction. However, I dont know how to apply the throw back force to the marble. I have tried with AddExplosionForce, but that only throws the marble up in the y axis. However, I would like it to throw back on the x and z axis when the marble rolls on the mine, and only throw the marble up, if the marble falls to the mine.

How should I do it?

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 tnetennba · Aug 09, 2011 at 03:48 PM 0
Share

What values are you using when you call the function?

avatar image Dreeka · Aug 09, 2011 at 04:14 PM 0
Share

I have tried with power = 25, radius = 3, and upwards$$anonymous$$odifier with both 3.0 and 0.0

avatar image tnetennba · Aug 09, 2011 at 04:20 PM 0
Share

And what about the position of the explosive force?

avatar image Dreeka · Aug 09, 2011 at 04:58 PM 0
Share

I use the position of the $$anonymous$$e

3 Replies

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

Answer by Blankzz · Aug 10, 2011 at 01:13 AM

Try getting your force vector from Rigidbody.velocity. Normalize it, invert it and multiply it by an explosion strength factor. Use forcemode.acceleration so you don't have to take the mass of the marble into consideration.

 public var explosionStrength : float = 10.0f;
 
 function OnTriggerEnter (target_ : Collider)
 {
     var forceVec : Vector3 = -target_.rigidbody.velocity.normalized * explosionStrength;
     target_.rigidbody.AddForce(forceVec,ForceMode.Acceleration);
 }
Comment
Add comment · Show 3 · 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 Dreeka · Aug 10, 2011 at 09:36 AM 0
Share

Thanks, this is working fine :) Thanks for the other replies aswell.

avatar image siddharth3322 · Aug 31, 2014 at 08:23 AM 0
Share

Thanks for this implementation, it worked for me as expected.

avatar image AdamHalo · Dec 21, 2014 at 10:04 PM 0
Share

Curiously this worked for me only when I changed from Force$$anonymous$$ode.Acceleration to Force$$anonymous$$ode.Impulse (taken from the other answer below).

avatar image
1

Answer by MPink · Aug 09, 2011 at 04:40 PM

Thats very strange. Cant say iv used AddExplosionForce yet myself but i can see the problem your having. I would expect the 2 Force functions below to do much the same thing but they dont.

public var force : float = 10.0f;

function OnTriggerEnter (target_ : Collider) { var vec : Vector3 = target_.transform.position; vec -= this.transform.position; vec.Normalize(); vec *= this.force; target_.rigidbody.AddForce(vec,ForceMode.Impulse); // target_.rigidbody.AddExplosionForce(force,target_.transform.position,10,0,ForceMode.Impulse); }

Hope they helps you even if it dose not explain explain how to use ExplosionForce correctly.

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 Dreeka · Aug 09, 2011 at 04:58 PM 0
Share

I have copied the following code to the $$anonymous$$e, however, nothing is happening. The trigger is registered, but nothing else happens. If I remove Force$$anonymous$$ode.Impulse, it works, but sometimes it launch the ball to a different way than it should.

avatar image
1

Answer by JUnityer · Aug 09, 2011 at 04:48 PM

Hey,

I don't know how to do that kind of effect myself, but I suggest checking out the Detonator package. You may have already seen / tried this somewhere, but maybe you could use parts from this somehow. There is a "shockwawe" component inside that makes the objects around the explosion fly away, so take a look at it.

You could make the mines with this one easily. But if you want to make it 100% yourself, well, go ahead and do it! : ) I highly appreciate that kind of work, but just wanted to suggest you an easy way.

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 Dreeka · Aug 09, 2011 at 04:59 PM 0
Share

I have tried it, however these explosions are launching the marble up aswell.

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

Prevent Rigidbody from Climbing Steep Slopes using Forces (C#) 0 Answers

Objects continue to have force applied after escaping force range 1 Answer

How to fix/clamp rigidbody dir vector, despite Force dir 1 Answer

How to change velocity of object which move by Rigidbody. 1 Answer

Movement Physics: Max Speed and Momentun 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