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 oliver-jones · Jun 30, 2013 at 01:34 PM · rigidbodyforceexplosioncoin

Add Explosive Force - Coins

Hello,

I have a bunch of gold coins that initiate when I kill an enemy.

I want to be able to have the coins disperse from the kill point (like an mini-explosion), and then after a few seconds, the coins move towards the player.

So I have this function that is called when the enemy die:

 function InitCoins(){
 
     var coins = new Array();
 
     for(var i = 0; i < 5; i++){
 
         var coin : Transform;
         coin = Instantiate(coinPickup, transform.position, transform.rotation);
 
         coin.gameObject.GetComponent(CoinPickup).player = target;
         coin.gameObject.GetComponent(CoinPickup).timer = (i);
 
 
         var radius = 10.0;
         var power = 100.0;
         var explosionPos : Vector3 = coin.transform.position;
 
         coin.rigidbody.AddExplosionForce(power, explosionPos, radius, 10.0);
 
     }
 
 }

The explosion force doesn't seem to do anything? I have the timer and move to player sorted:

 function Start () {
 
     var random = Random.Range(4, 7);
 
     yield WaitForSeconds(timer / random);
     canMove = true;
 
 }
 
 function FixedUpdate () {
 
     
     if(canMove){
 
         var lookPos = player.transform.position - transform.position;
         var rotation = Quaternion.LookRotation(lookPos);
 
         transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 10);
 
         //Move towards player - via transform, or rigidbody
         //transform.Translate(Vector3.forward * speed * Time.deltaTime);
         //rigidbody.AddRelativeForce (Vector3.forward * 10);
 
     }
     
 }

I mainly just want to get the mini explosion effect working to begin with.

Things to note: The game is a top down game, so all Y movements are blocked, as well as X and Z rotations.

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

1 Reply

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

Answer by robertbu · Jun 30, 2013 at 02:54 PM

If you left the mass of your coins at 1.0, a force of 100 will not overcome gravity. In addition, because you are applying the force at the position of the object (and using upwardsModifier), you can get the same effect by:

 rigidbody.AddForce(Vector3.up * 500.0);

That is, you are not getting the use of a linear dropoff in force because the explosion is happening at the position of the coin.

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

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

Directional Explosion 1 Answer

Make grenade apply force to rigidbodies around it 3 Answers

Decrease ExplosionForce and damage continously by distance 2 Answers

Exploide GameObjects Into BrokenParts : Unity 1 Answer

How to calculate force from explosion on a rigidbody 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