Hi everyone,
I am using Unity to model residential building failures under hurricane wind and water loading. I currently have a script that reads a text file and if a certain value in that text file is equal to zero then the roof cover component (3D cube game object) fails. When this happens, the isKinematic on the rigidbody for that game object is set to false so that it will fly off in simulated wind. Where I am having trouble is I want to add a rotation in the z axis to make the failure and effect of flying through the wind more realistic. However, I am unable to make the game object rotate in the z direction. I would think it would be a simple transform.Rotate but this is not working. Do you have any suggestions or see any problems with what I am doing? I have attached the code I have applied to the game object below. Thank you for your help!
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class Roof_Cover_13 : MonoBehaviour
{
public string txtFile = "Roof_Cover_Failure";
string txtContents;
int[] stress;
Rigidbody rb;
// Start is called before the first frame update
void Start()
{
System.Random rnd = new System.Random();
int delay = rnd.Next(5, 30);
rb = GetComponent<Rigidbody>();
rb.isKinematic = true;
char[] delimiterChars = { '\n' };
txtContents = File.ReadAllText(@"C:\Users\giova\Dropbox\Research\Graduate School\Roof_Cover_Failure");
string[] splitTxt = txtContents.Split(delimiterChars);
stress = new int[splitTxt.Length];
for (int j = 0; j < splitTxt.Length; j++)
{
stress[j] = System.Convert.ToInt32(splitTxt[j]);
}
Invoke("Failed", delay);
}
void Failed()
{
if (stress[85] == 0)
{
rb.isKinematic = false;
transform.Translate(0.3f, 0.2f, 0);
}
}
private void LateUpdate()
{
if (rb.isKinematic == false)
{
transform.Rotate(0, 0, -1);
}
}
}