- Home /
Tornado throwing back force after pulling
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!
Answer by Zodiarc · Oct 28, 2016 at 02:44 PM
You could also make a more physics based approach. There are 2 forces which you have to deal with. The force which pulls the ubject towards the tornado and the centrifugal force. At first any object near the tornado could have the centrifugal force of 0 and being pulled towards the tornado. You calculate the pull force and the centrifugal force from this point on. If the centrifugal force is greater then the pull, the objects flys away. Or you could combine the two forces and at some point when the centrifugal force will be greater and switch the direction of the combined force.
That's a good idea, however, I cant understand how I could add centrifugal force. Do you ?
Thanks!
Edit: oh and how could i make a mass dependent pull force?
There are formulas how to calculate these things
http://www.engineeringtoolbox.com/centripetal-acceleration-d_1285.html
The pull force could be done by using the wind speed and the mass of the object. The heavier the object the harder it is for the tornado to pull it in. But I'm not good at math at all, so I can't directly answer this.
Your answer
Follow this Question
Related Questions
How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers
Artificial Gravity 2 Answers
What's the Rigidbody's gravity unit? 1 Answer
Problems making a glider 3 Answers