Professional Documents
Culture Documents
Tornadotut
Tornadotut
com/blog/unity-3d-tornado-physics
BLOG
Sharp Coder is reader-supported, meaning when you buy through links on our site, we may earn an affiliate commission.
Unity 3D Tornado Physics Get notified when there are new tutorials, directly
to your inbox.
SUBSCRIBE
Search
SUGGESTED POSTS
Unity 2D Coin Collecting
Unity Countdown Timer
Unity Cinemachine and Timeline Tutorial
How to Install Unity and Create a New Project
Unity version used in this tutorial: Unity 2018.3.0f2 (64-bit) Unity How to Create a Script
Unity How to Attach a Script or a Component to a
Step 1: Create all the necessary scripts GameObject
YOU DO NOT HAVE TO DO
EVERYTHING YOURSELF Unity Mini Game | CUBEavoid
This tutorial requires 2 scripts:
Search from thousands of ready-to-use
Unity assets. POPULAR POSTS
SC_Caught.cs
Visit Asset Store Unity FPS Controller
Unity 2D Character Controller
//This script is attached automatically to each Object caught in Tornado
1 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
Third-Person Camera in Unity
using UnityEngine;
Make FPS With Enemy AI in Unity
public class SC_Caught : MonoBehaviour Make a Multiplayer Game in Unity Using PUN 2
{
Unity Openable Classic and Sliding Doors
private SC_Tornado tornadoReference;
private SpringJoint spring; Endless Runner in Unity
[HideInInspector]
public Rigidbody rigid;
void FixedUpdate()
{
//Rotate object around tornado center
Vector3 direction = transform.position - tornadoReference.transform.position;
//Project
Vector3 projection = Vector3.ProjectOnPlane(direction, tornadoReference.GetRotationAxis());
projection.Normalize();
Vector3 normal = Quaternion.AngleAxis(130, tornadoReference.GetRotationAxis()) * projection;
normal = Quaternion.AngleAxis(tornadoReference.lift, projection) * normal;
rigid.AddForce(normal * tornadoReference.GetStrength(), ForceMode.Force);
2 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
//Initialize the spring
spring = gameObject.AddComponent<SpringJoint>();
spring.spring = springForce;
spring.connectedBody = tornadoRigidbody;
spring.autoConfigureConnectedAnchor = false;
//Set initial position of the caught object relative to its position and the tornado
Vector3 initialPosition = Vector3.zero;
initialPosition.y = transform.position.y;
spring.connectedAnchor = initialPosition;
}
SC_Tornado.cs
using System.Collections.Generic;
using UnityEngine;
[Tooltip("Angle that is added to the object's velocity (higher lift -> quicker on top)")]
[Range(0, 90)]
public float lift = 45;
[Tooltip("The force that will drive the caught objects around the tornado's center")]
3 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
List<SC_Caught> caughtObject = new List<SC_Caught>();
r = GetComponent<Rigidbody>();
r.isKinematic = true;
}
void FixedUpdate()
{
//Apply force to caught objects
for (int i = 0; i < caughtObject.Count; i++)
{
if(caughtObject[i] != null)
{
Vector3 pull = transform.position - caughtObject[i].transform.position;
if (pull.magnitude > maxDistance)
{
caughtObject[i].rigid.AddForce(pull.normalized * pull.magnitude, ForceMode.Force);
caughtObject[i].enabled = false;
}
else
{
caughtObject[i].enabled = true;
}
}
}
}
4 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
{
caughtObject.Add(caught);
}
}
if (caughtObject.Contains(caught))
{
caughtObject.Remove(caught);
}
}
}
YOU DO NOT HAVE TO DO // get the angle for this step (in radians, not degrees)
EVERYTHING YOURSELF float angle = i * Mathf.PI * 2;
Search from thousands of ready-to-use
Unity assets.
// the X & Y position for this angle are calculated using Sin & Cos
Visit Asset Store float x = Mathf.Sin(angle) * maxDistance;
float z = Mathf.Cos(angle) * maxDistance;
5 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
Gizmos.color = Color.cyan;
for (int i = 0; i < positions.Length; i++)
{
if (i == positions.Length - 1)
{
Gizmos.DrawLine(positions[0], positions[positions.Length - 1]);
}
else
{
Gizmos.DrawLine(positions[i], positions[i + 1]);
}
}
}
}
• Create a new GameObject (GameObject -> Create Empty) and name it "Tornado"
• Create another GameObject and name it "Particles", move it inside "Tornado" and change its position to (0, 0, 0)
• Add ParticleSystem component to "Particles" GameObject
• In Particle System enable these modules: Emission, Shape, Velocity over Lifetime, Color over Lifetime, Size
over Lifetime, Rotation over Lifetime, External Forces, Renderer.
6 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
2. Assign the values for each Particle System module (Check Screenshots below):
Emission module:
7 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
(2DO
YOU DO NOT HAVE TO Gray colors at each end and 2 White colors in the inner part)
EVERYTHING YOURSELF
Search from thousands of ready-to-use
Unity assets.
Size over Lifetime module:
8 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
This module does not need any changes, just leave the default values.
Renderer module:
9 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
10 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
But as you can see it does not look like Tornado at all, that's because we have one more component to add,
which is Particle System Force Field, this component is needed to simulate the circular wind:
11 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
12 of 14 10/18/21, 2:51 PM
Unity 3D Tornado Physics | Sharp Coder Blog https://sharpcoderblog.com/blog/unity-3d-tornado-physics
To test it simply create a Cube and add a Rigidbody component to it, then place it somewhere inside the Trigger area.
Once you press Play the Cube should be pulled in by the Tornado:
Source
� TornadoSystem.unitypackage 239.71 KB
14 of 14 10/18/21, 2:51 PM