- Home /
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);
}
}
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!
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
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 ();
}
}
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!
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?
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
Follow this Question
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