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 Jdogmaster · Apr 13, 2018 at 10:55 PM · explosionpushthrowpullpushback

throwing objects

so ive built a tornado and when it comes in contect with a house i built in the game it destroyes it and causes all the debris to be pulled in and rotate around it. this works great when making a small tornado as it releases the debris. but when i build a large tornado it just holds on to all the debris and never lets go of it. to make my game more realistic i need the tornado to release the debris, how can i do this? btw my tornado is made up of multiple capsul colliders leading to the center of the tornado. the pull force and rotation speed increace from the outermost collider to the center collider. the center collider has a repelling force so all the debris doesent just collect at the center of the tornado and instead just rotate around it from that distance. but i really need the tornado to release the gameobjects it picks up so it doesent just have everything inside it.

here is the script i attach to each collider in the tornado to give it pull and rotational force. if you want a better idea on how my colliders are put in the tornado watch this https://www.youtube.com/watch?v=0kUX3P-If1E private GameObject PullOBJ;

       public float PullSpeed;
 public float objRotationSpeed;
 public float rotation;
 public float PullStrength;


 public void OnTriggerStay (Collider coll)
 {
     if (coll.gameObject.tag == "Untagged") {
         PullOBJ = coll.gameObject;

         PullOBJ.transform.position = Vector3.MoveTowards (PullOBJ.transform.position, this.transform.position, PullSpeed * Time.deltaTime);
         PullOBJ.transform.RotateAround (transform.position, Vector3.up, Time.deltaTime * rotation);
         PullOBJ.transform.Rotate (Vector3.left, 45 * Time.deltaTime * objRotationSpeed);
     }

 

 
 }
 

         
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

Answer by ThePixelatedSword · Apr 13, 2018 at 11:00 PM

You could add a rigidbody to all of the GameObjects and then make the tornado output a force. This should make it look like the house are being thrown. If you need help writing a script to do that I'll be glad to help!

Comment
Add comment · Show 7 · 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 Jdogmaster · Apr 13, 2018 at 11:08 PM 0
Share

yess i would love help thx so much!

avatar image Jdogmaster · Apr 13, 2018 at 11:14 PM 0
Share

k so to give you a better idea how my game works so far ill tell you how things are destroyed. So my tornado can only pick up gameobjects with the tag of 'Untagged'. So initially my houses are kineomatic and are marked otherwise. but when my tornados colliders come over the house if the colliders pullstrength is greater than my houses Durability, then the house will be replaced with a shattered version of itself. and all the shattered pices are marked as 'Untagged' so they get sucked into the tornado. btw my house has many different parts of it so the roof durability is relativly weak so it is destroyed by the outer collider of the tornado. tornado. then other parts of the house have various durrability levels. some of witch are stronger than the tornados pullstrength. but if those parts are hit with enough force by debris, they can also be destroyed. hopefully this all makes sence :D

avatar image Jdogmaster · Apr 13, 2018 at 11:15 PM 0
Share

here is the script that i attatch to my structures public GameObject debrisPrefab; public float strength; public float Durability; private bool isCloned;

 void On$$anonymous$$ouseDown() {
     Destroy$$anonymous$$e ();
 }

 void OnCollisionEnter(Collision collision ) {
     
     
     if (collision.relativeVelocity.magnitude > strength) {
         Destroy$$anonymous$$e ();
     }

 }
     void Destroy$$anonymous$$e () {

         if (debrisPrefab && !isCloned) {
             
             Instantiate (debrisPrefab, transform.position, transform.rotation);

         }
         isCloned = true;
         Destroy (gameObject);

     }
 void OnTriggerEnter (Collider coll) {
     if (Durability <= coll.gameObject.GetComponent<TornadoVortex> ().PullStrength) {
         Destroy$$anonymous$$e ();
     }



         


 }
avatar image ThePixelatedSword · Apr 14, 2018 at 12:13 AM 0
Share

You need to add add a constant force to the broken pieces of the houses. Here's a script to put onto the tornado. This adds an explosion force on all of the pieces with rigid bodies within the variable of radius. You can tweak this if you need.

   using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     
     public class Tornado : $$anonymous$$onoBehaviour {
         public float explosionForce = 4;
         public float radius = 20;
         public float multiplier = 2;
     
         public void Update () {
             var cols = Physics.OverlapSphere(transform.position, radius);
             var rigidbodies = new List<Rigidbody>();
             foreach (var col in cols)
             {
                 if (col.attachedRigidbody != null && !rigidbodies.Contains(col.attachedRigidbody))
                 {
                     rigidbodies.Add(col.attachedRigidbody);
                 }
             }
             foreach (var rb in rigidbodies)
             {
                 rb.AddExplosionForce(explosionForce*multiplier, transform.position, radius, 1*multiplier, Force$$anonymous$$ode.Impulse);
             }
         }
     }

I hope this helps!

avatar image Jdogmaster ThePixelatedSword · Apr 14, 2018 at 12:51 AM 0
Share

k ill let you know how it goes!

avatar image Jdogmaster ThePixelatedSword · Apr 14, 2018 at 01:08 AM 0
Share

the tornado is still holding on its pretty big. mabe i could make a script that after an object has been picked up for a certian amount of seconds it changes its tag, so the tornado cant pick it up, then after its left the tornado its tag changes back so it can be picked up again if the tornado returs. would that work?

avatar image Jdogmaster ThePixelatedSword · Apr 14, 2018 at 01:25 AM 0
Share

actually in a way it is working when the objects get sucked into the tornado they will start flinging out but it also makes the object rotation around the tornado very jagged and not smooth rotation, i think its because of the explosive force

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

77 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 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 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 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 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 avatar image avatar image

Related Questions

Cube collision problems when held 0 Answers

Amnesia like objects, in unity. 2 Answers

3rd Person Throwing Grenade Question 0 Answers

adding Up force 0 Answers

How to make Jedi Push and Pull objects (video) 2 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