making objects react to colliders without tag C#
ok so i have a tornado that sucks up objects and rotates them around the tornado. the tornado has a few colliders each with a different amount of pullforce depending on how far it is from the tornado center. originaly i could make the tornado destroy objects by using objects picked up by the tornado using a collision script. so if my house is hit by the tornado with enough force it destroyes it. my tornado can only pick up objects with the tag of 'untagged'. my house has a script otherwise so it cant be picked up. but then if it his hit by an object with enough force, the house is replaced by a shattered version of itself, and all the shattered pices are tagged as 'untagged' so they are picked up by the tornado. but i want the tornado to also be able to destroy objects even if it hasent picked up any objects to throw at the houses. so in the tornado script there is pullstrength and in the house script there is durability. so i want if the pullstrength of a collider in the tornado is higher than a houses durability it will be destroyed. this is the portion of my script i made to just do that. there are no errors in it but it just isnt doing anything and i wasnt sure why it wasnt working. btw this isnt the full script. this is the script that goes on my house.
public float Durability;
private bool isCloned;
void DestroyMe () {
if (debrisPrefab && !isCloned) {
Instantiate (debrisPrefab, transform.position, transform.rotation);
}
isCloned = true;
Destroy (gameObject);
}
void OnEnter(Collision collision) {
if (Durability <= collision.gameObject.GetComponent<TornadoVortex> ().PullStrength) {
DestroyMe ();
}
}
Please provide the code for the tornado since the way PullStrength or "objects thrown at the houses" is implemented isn't clear.
Also, please do some formatting for easier reading :)
You mentioned you want the tornado to be able to cause damage before it has picked up any objects. Does the tornado have a collider on it, or are there only colliders on the objects it picks up?
yes the tornado has multiple colliders in it extending from the center the tornado colliders use the tornadovortex code. if you want a clearer pickture of what the colliders look like around the tornado, watch this video https://www.youtube.com/watch?v=0kUX3P-If1E
Answer by Jdogmaster · Apr 11, 2018 at 01:00 PM
here is the Tornado Vortex Script
private GameObject PullOBJ;
public float PullSpeed;
public float objRotationSpeed;
public float rotation;
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);
}
}