- Home /
Tornado Simulator
Hey, so im trying to recreate the tornado in this video https://www.youtube.com/watch?v=IlhdLQ5NU5E In the comments they guy who made the video said that he uses 4 forces - Force 1 suction force that makes objects move towards the tornado - Force 2 rotational force to make stuff spin around the tornado - Force 3 lift force to move objects up - Force 4 centrifugal force to make objects move away from the tornado
In my script i have applied all of these forces. my tornado does work and sucks up objects but the problem im having is that, i have to have a strong inward force, and a low rotational force to keep my objects in a stable rotation for a few seconds. but when i have a strong inward force, it takes about 2 seconds for the objects to actually start rotating around the tornado and i dont get the wraping effect like in the tornado in the video. I need to figure out how to have higher rotation with lower inward force. the reason for this is so that objects will imidetly start rotating around the tornado without getting sucked in first. but my current issue with that right now is that, if i have a low inward force, and higher rotational force, objects will immidietly exit the tornadoes collider before they can rotate very much. so i need to figure out how to stabalize this so i get that nice wrapping effect like in the video.
const float G = 667.4f;
public float TornadoPower;
public float TornadoRotation;
public float MaxForce = 100;
public float MinForce = -50;
public float upforce;
float forceMagnitude;
Vector3 vector;
public Rigidbody rb;
GameOBJ thisOBj;
void OnTriggerStay(Collider other)
{
if (other.GetComponent<GameOBJ>())
{
Attract(other.GetComponent<GameOBJ>());
}
}
void Attract(GameOBJ objToAttract)
{
Rigidbody rbToAttract = objToAttract.GetComponent<Rigidbody>();
GameOBJ Attractforce = objToAttract.GetComponent<GameOBJ>();
Vector3 direction = rb.position - rbToAttract.position;
float distance = direction.magnitude;
float signedAngle = Vector3.SignedAngle(direction.normalized, Vector3.forward, Vector3.up);
Quaternion rotatedAngle = Quaternion.AngleAxis(270 - signedAngle, Vector3.up);
Vector3 newDirection = rotatedAngle * Vector3.forward;
forceMagnitude = G * (TornadoPower * rbToAttract.mass * Attractforce.weight) / Mathf.Pow(distance, 2);
{
if (forceMagnitude >= MaxForce)
{
forceMagnitude = (MaxForce * 2) - forceMagnitude;
if (forceMagnitude <= MinForce)
{
forceMagnitude = MinForce;
}
}
Vector3 force = direction.normalized * forceMagnitude;
float upwardforce = G * (upforce * rbToAttract.mass * Attractforce.weight) / Mathf.Pow(distance, 2);
rbToAttract.AddForce(Vector3.up * upwardforce);
rbToAttract.AddForce(newDirection * TornadoRotation);
rbToAttract.AddForce(force);
}
}
}
Your answer
Follow this Question
Related Questions
Rotate an object based on vectors. 1 Answer
add force at position with respect to rotation 1 Answer
I need Some Info About Rotation And Pvot 0 Answers
Rotational Force 0 Answers
How to rotate a ship based on gravity around a planet? 1 Answer