Here’s my scripts:
I add this script to my objects that I want to be pulled by the tornado:
using UnityEngine;
using System.Collections;
public class PullObject : MonoBehaviour {
public bool isClose = false;
public void OnTriggerEnter(Collider other)
{
Vector3 dir = transform.position - other.GetComponent<Transform> ().position;
if (other.gameObject.tag == "Tornado") {
isClose = true;
}
}
}
Then I add this script to my tornado’s center:
using UnityEngine;
using System.Collections;
public class TornadoVortex : MonoBehaviour {
private GameObject PullOBJ;
public float PullSpeed;
public float objRotationSpeed;
public void OnTriggerStay(Collider coll)
{
if (coll.gameObject.tag == "Pullable") {
PullOBJ = coll.gameObject;
PullObject currentObject = coll.gameObject.GetComponent<PullObject> ();
if (currentObject.isClose == false) {
PullOBJ.transform.position = Vector3.MoveTowards (PullOBJ.transform.position, this.transform.position, (PullSpeed / 2) * Time.deltaTime);
PullOBJ.transform.RotateAround (transform.position, Vector3.up, Time.deltaTime*-20);
PullOBJ.transform.Rotate (Vector3.left, 45 * Time.deltaTime * objRotationSpeed);
}
}
}
}
The reason why I use tag detection is to add multiple colliders around my tornado with my script attached, but only the one at the center of it having the tag “Tornado” attached to it. This way I can put different pulling forces to my different colliders in the editor, but only the one in the center (with tornado tag) will make objects stop to be pulled.
So Basically, as long as the object has not reached the center of the tornado, it is getting moved towards it, while also being orbiting around it and rotating on itself to simulate the wind making it spin.
Now I would like to find a way to make the object fly out of the tornado, basically getting pushed out of it, but following the movement it came from, while falling to the ground due to gravity. If I use the current script, I can make it fall to the ground when isClose = 1, but it falls straight down, instead of falling slowly while still rotating a bit. Also, I need to find a way to make it pullable again as soon as it got out of the tornado radius, in case it comes back on the object.
If by any “chance” the tornado comes back on the object, it has to be pullable again.
Here’s what I’ve done so var VS what I’m looking for :
Hope anyone can help me here!
THANKS SO MUCH!
