- Home /
The question is answered, right answer was accepted
Tornado physics
Right know im building a tornado but i cant figure out how to add physics to it. The forces i need are: - Force 1 is a suction force that makes the stuff move towards the tornado - Force 2 is a rotation force to make the stuff spin around the tornado, which I apply perpendicular to the center of the tornado - Force 3 is a lift force to make the stuff move up - Force 4 is a centrifugal force to make the stuff move away from the tornado Im not really familliar with c# scripting because im still a bit of a beguinner. So please let me know how to add these forces to my tornado.
As this is the Third time youve posted this question, Ive deleted the others. Stop duplicate posting : - This is a warning.
Answer by KittenSnipes · Mar 24, 2018 at 01:46 AM
This script slowly drags a object at a certain range and also rotates it when it interacts with the tornado object:
//Float used to set the speed of the suction of the tornado
public float pullInSpeed = 0.1f;
//Float used to set the speed of the rotation of the tornado
public float rotateSpeed = 1.25f;
//Radius the suction of the tornado reaches
public float radius = 20;
//Holds the objects within the radius
public List<GameObject> objectsToPullIn;
//Sets whether the objects is being pulled or not
public Dictionary<GameObject, bool> objectsPulled;
void Start()
{
//Instantiate Dictionary and List for use
objectsToPullIn = new List<GameObject>();
objectsPulled = new Dictionary<GameObject, bool>();
}
void RemoveObjectsFarAway()
{
//For each of the gameobjects in objectsToPullIn
foreach (GameObject thing in objectsToPullIn)
{
//Check if the distance between the objects position and the tornados position is greater than the suctions radius
if (Vector3.Distance(thing.transform.position, transform.position) > radius)
{
//And if that is true then remove the object from being sucked in
objectsToPullIn.Remove(thing);
}
}
}
void GetObjectsToPullIn()
{
Collider[] objects = Physics.OverlapSphere(GetComponent<Collider>().bounds.center, radius);//GetComponent<Collider>().bounds.extents.magnitude);
//For each object
for (int i = 0; i < objects.Length; i++)
{
//If that object is not already contained in the objectsToPullIn list
//the object does not equal the tornado, and if it contains a
//rigidbody component
if (!(objectsToPullIn.Contains(objects[i].gameObject))
&& objects[i].gameObject != gameObject
&& objects[i].GetComponent<Rigidbody>() != null)
{
//Then add it to the objects to pull in list
objectsToPullIn.Add(objects[i].gameObject);
//And make sure to set that the object has not been pulled all the way in yet
objectsPulled.Add(objects[i].gameObject, false);
}
}
}
void PullObjectsIn()
{
//For each gameobject in objectsToPullIn
foreach (GameObject thing in objectsToPullIn)
{
//If the object has been pulled in
if (objectsPulled[thing] != true)
{
//Then move it towards the tornado
thing.transform.position = Vector3.MoveTowards(thing.transform.position, transform.position, thing.GetComponent<Rigidbody>().mass * Time.deltaTime * pullInSpeed);
}
}
}
void RotateObjects()
{
//For each of the gameobjects that have been classified as being pulled in or not
foreach (GameObject thing in objectsPulled.Keys)
{
//If they are pulled in
if (objectsPulled[thing] == true)
{
//Then rotate it around the tornado
thing.transform.RotateAround(Vector3.zero, transform.up, thing.GetComponent<Rigidbody>().mass * rotateSpeed * Time.deltaTime);
}
}
}
void OnCollisionEnter(Collision other)
{
//If the object is contained in the object to pull in list
if (objectsToPullIn.Contains(other.gameObject))
{
//Then set the object as being pulled in to the tornado
objectsPulled[other.gameObject] = true;
//Rotate that shit
RotateObjects();
}
}
void OnCollisionStay(Collision other)
{
//If the object is contained in the object to pull in list
if (objectsToPullIn.Contains(other.gameObject))
{
//Then set the object as being pulled in to the tornado
objectsPulled[other.gameObject] = true;
//Rotate that shit
RotateObjects();
}
}
void OnCollisionExit(Collision other)
{
//If the object is contained in the object to pull in list
if (objectsToPullIn.Contains(other.gameObject))
{
//Then set the object as not being pulled in to the tornado
objectsPulled[other.gameObject] = false;
}
}
void Update()
{
//Each update:
//Run these methods
RemoveObjectsFarAway();
GetObjectsToPullIn();
PullObjectsIn();
RotateObjects();
}
Hopefully this stuff helps out a little bit. I mean all it does is pull the objects in and rotate them when they are in contact with the tornado.
Sweet ya I will try it out right away! Let u know how it oges
So how do i get objects to react to the tornado, I added the script to the tornado but the tornado just dissapeared and the object didnt move? Do i need to add a script to the objects? @$$anonymous$$ittenSnipes
Im going to send a video. $$anonymous$$aybe that can help
Thanks so much man ur the best! i will watch it right away!
Ok sure I will check it out when it is sent :D
Wait sorry i know im a noob, but when i added the script it didnt pull up the like pull factor and rotation factors so i think i did something wrong ill send a screen shot in a sec so u can let me know if i did it right
Answer by marcrem · Mar 23, 2018 at 09:04 PM
I am currently making a tornado simulation. Check out vectoraygen.
Answer by bhavinbhai2707 · Mar 23, 2018 at 09:15 PM
well for the suction part you can watch this video. Click here to watch
Answer by Jdogmaster · Mar 23, 2018 at 09:18 PM
cool i can use that for suction, now i just need the other 3