# Tornado Physics Question - how to negate RotateAround?

Discussion in 'Physics' started by SnakeByte24, Aug 13, 2019.

1. ### SnakeByte24

Joined:
Sep 30, 2018
Posts:
4
Hi there, if anyone can lend any help regarding this tornado physics question I'd be really grateful!

I have a tornado set up with a sphere collider where anything entering & staying sets a bool to true, and if the bool is true it runs this function:

Code (CSharp):
1. void VacuumItems()
2.     {
3.         foreach (GameObject pulledObject in ItemsToVacuum)
4.         {
5.             if (pulledObject.GetComponent<Collider>().bounds.Intersects(GetComponent<Collider>().bounds))
6.             {
7.                 explosionPower = explosionPowerCurve.Evaluate(((Time.time * 0.1f) % explosionPowerCurve.length));
8.                 pulledObject.GetComponent<Rigidbody>().AddExplosionForce(explosionPower, pullingCentre.transform.position, explosionRadius, 1F, ForceMode.Impulse);
9.                 pulledObject.GetComponent<Transform>().RotateAround(pullingCentre.transform.position, -pullingCentre.transform.position, Random.Range(0.0f, 180.0f) * Time.deltaTime);
10.
11.             }
12.
13.         }
14.
15.     }
This applies a negative explosion force sucking in the object and rotates it around the tornado with RotateAround.

Then for OnTriggerExit for the sphere collider I set the bool to false and do:

Code (CSharp):
1. pulledObject.GetComponent<Rigidbody>().velocity = Vector3.zero
As you might expect though, this just drops the object where it is dead in its tracks, does anyone know how I can negate the RotateAround but have the object maintain the rest of its velocity? i.e. the object is flung out of the tornado along a realistic trajectory instead of zeroing its velocity completely?

Many thanks for any ideas and please forgive any newbish questions I'm still learning!

2. ### Aseemy

Joined:
Aug 22, 2015
Posts:
141
You shouldn't use RotateAround on a Non-Kinematic RigidBody, try to create the rotation effect with forces themselves and when it triggers the exit then just stop the rotation forces so it will maintain its current velocity.

If you think this is not the way to go then keep your current setup, but after the OnTriggerExit is hit, wait for 1 frame and calculate the direction of the transform movement by comparing the position values from the previous frame to the current one. Then stop the rotation and add your own force in that direction.

Last edited: Aug 13, 2019
MaximumTre and SnakeByte24 like this.
3. ### SnakeByte24

Joined:
Sep 30, 2018
Posts:
4
Thank you for the reply!

I'm starting to realise my shortcut for faking centrifugal force is causing the problem. I have been told I shouldn't mix Rb vector changes and transform vector changes so I will have to look into how to create the rotation through forces

4. ### marcrem

Joined:
Oct 13, 2016
Posts:
153
What kind of game are you working on? Im leading a project which is a storm chasing game. We had such physics interactions before so I might be able to help. We had to write our own custom fake physics engine as we needed to move hundreds of objects, so it's a different thing. But if you're moving a couple objects at a time, I can guide you.

5. ### SnakeByte24

Joined:
Sep 30, 2018
Posts:
4
Hi thanks Marcrem that's kind of you!

It wouldn't be Storm Chasers would it? That's on my wishlist.

Ultimately I wanted to the tornado to interact with destructible environments, so yes potentially hundreds of objects.

For proof of concept and first steps though, moving a couple of objects will suffice.

6. ### marcrem

Joined:
Oct 13, 2016
Posts:
153
Hi, no it's called outbrk (look for outbrkgame on social networks). We actually have weather simulated entirely, even the cloud shapes and structures behave like real storms, and data is from real weather data. We have a 625 square km world and its multiplayer. Although storm chasers looks fun, what we're doing is more like an actual storm chasing experience. Its like SC is the arcade version of the storm chasing concept, and outbrk is the simulator. If you ask me, the world needed both games

I'll get back to you on a quite cool solution to handle the physics for your tornado as soon as im back home. Cheers!

7. ### SnakeByte24

Joined:
Sep 30, 2018
Posts:
4
That sounds amazing and something I'd be highly interested in. Would love to keep up to date with your development, the game looks amazing and lots of fun!

8. ### marcrem

Joined:
Oct 13, 2016
Posts:
153
So depending on how many objects you're planning to move, here's a nice solution that could work for you.

Using this asset, you can affect rigibodies with very complex trajectories, and you can put multiple vector fields on top of each other. The asset comes with many example vector fields, including rotative ones, so you should be able to set up your tornado quite easily. You can also get their software and create your own vector fields.

https://assetstore.unity.com/packag...or-field-plugin-fga-3d-texture-support--97239

The asset is well written and extremely well supported as well.

Cheers!