148 lines
3.9 KiB
C#
148 lines
3.9 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Artngame.TEM
|
|
{
|
|
public class TornadoDebug : MonoBehaviour
|
|
{
|
|
public GameObject skeletonCylinder;
|
|
|
|
public GameObject chaseObj;
|
|
|
|
public GameObject chaseRotateObj;
|
|
|
|
public GameObject targetObj;
|
|
|
|
[Header("Tornado data")]
|
|
public float tornadoSpeed = 10f;
|
|
|
|
public float tornadoRotSpeed = 1f;
|
|
|
|
public float tornadoHeight = 50f;
|
|
|
|
public int pieces = 10;
|
|
|
|
public float m;
|
|
|
|
public float k;
|
|
|
|
public float c;
|
|
|
|
public float aboveFactor = 1f;
|
|
|
|
public float belowFactor = 1f;
|
|
|
|
public float chaseFactor = 1f;
|
|
|
|
[NonSerialized]
|
|
public Transform[] skeletonPiecesArray;
|
|
|
|
private Vector3[] posNew;
|
|
|
|
private Vector3[] posOld;
|
|
|
|
private Vector3[] velArray;
|
|
|
|
private Vector3 oldChasePos;
|
|
|
|
private void Start()
|
|
{
|
|
BuildTornado();
|
|
posNew = new Vector3[pieces];
|
|
posOld = new Vector3[pieces];
|
|
velArray = new Vector3[pieces];
|
|
for (int i = 0; i < pieces; i++)
|
|
{
|
|
posNew[i] = Vector3.zero;
|
|
posOld[i] = skeletonPiecesArray[i].position;
|
|
velArray[i] = Vector3.zero;
|
|
}
|
|
chaseObj.transform.position = base.transform.position;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
MoveTornado();
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
TornadoDynamics();
|
|
}
|
|
|
|
private void BuildTornado()
|
|
{
|
|
skeletonPiecesArray = new Transform[pieces];
|
|
float num = tornadoHeight / (float)pieces;
|
|
float num2 = 0f;
|
|
for (int i = 0; i < pieces; i++)
|
|
{
|
|
GameObject gameObject = UnityEngine.Object.Instantiate(skeletonCylinder);
|
|
Vector3 localScale = skeletonCylinder.transform.localScale;
|
|
localScale.z = num / 2f;
|
|
gameObject.transform.localScale = localScale;
|
|
Vector3 position = base.transform.position;
|
|
position.y = num2;
|
|
gameObject.transform.position = position;
|
|
gameObject.transform.parent = base.transform;
|
|
skeletonPiecesArray[i] = gameObject.transform;
|
|
num2 += num;
|
|
}
|
|
}
|
|
|
|
private void TornadoDynamics()
|
|
{
|
|
Vector3 position = chaseObj.transform.position;
|
|
Vector3 position2 = chaseRotateObj.transform.position;
|
|
position.y = 0f;
|
|
float num = 0.02f;
|
|
for (int i = 0; i < pieces; i++)
|
|
{
|
|
_ = m;
|
|
Vector3 vector = posOld[i];
|
|
Vector3 zero = Vector3.zero;
|
|
zero = ((i != 0) ? ((i != pieces - 1) ? (((0f - this.k) * (vector - posOld[i - 1]) * belowFactor + this.k * (posOld[i + 1] - vector) * aboveFactor) / m) : (((0f - this.k) * (vector - position) + this.k * (posOld[i - 1] - vector) * belowFactor) / m)) : (((0f - this.k) * (vector - posOld[i + 1]) * aboveFactor - this.k * (vector - position2) * chaseFactor) / m));
|
|
zero -= c * velArray[i] / m;
|
|
posNew[i] = vector + num * velArray[i];
|
|
velArray[i] += num * zero;
|
|
}
|
|
for (int j = 0; j < pieces; j++)
|
|
{
|
|
Vector3 position3 = posNew[j];
|
|
position3.y = skeletonPiecesArray[j].position.y;
|
|
skeletonPiecesArray[j].position = position3;
|
|
posOld[j] = posNew[j];
|
|
}
|
|
for (int k = 0; k < pieces; k++)
|
|
{
|
|
if (k > 0)
|
|
{
|
|
skeletonPiecesArray[k].LookAt(skeletonPiecesArray[k - 1].position);
|
|
}
|
|
else
|
|
{
|
|
skeletonPiecesArray[k].LookAt(skeletonPiecesArray[k].position + -Vector3.up);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void MoveTornado()
|
|
{
|
|
Vector3 target = targetObj.transform.position - chaseObj.transform.position;
|
|
Vector3 forward = Vector3.RotateTowards(chaseObj.transform.forward, target, tornadoRotSpeed * Time.deltaTime, 0f);
|
|
chaseObj.transform.rotation = Quaternion.LookRotation(forward);
|
|
chaseObj.transform.Translate(Vector3.forward * tornadoSpeed * Time.deltaTime);
|
|
float num = 40f;
|
|
float num2 = 300f;
|
|
Vector3 position = chaseObj.transform.position;
|
|
Vector3 position2 = chaseRotateObj.transform.position;
|
|
chaseRotateObj.transform.position += position - oldChasePos;
|
|
float magnitude = (position2 - position).magnitude;
|
|
Vector3 normalized = (position2 - position).normalized;
|
|
chaseRotateObj.transform.position += (num2 - magnitude) * normalized;
|
|
chaseRotateObj.transform.RotateAround(position, base.transform.up, num * Time.deltaTime);
|
|
oldChasePos = position;
|
|
}
|
|
}
|
|
}
|