Ok, I have tried to do my research to make this work for 3 days now and I need some help.
The end state = determine the revolutions per minute of a rotor blade.
I currently have a script that increments by 1 each time the blade passes 180 degrees.
I want to compare that value to determine the change per second. Any Ideas.
If anyone has a better solution to determine the RPM of a gameobject, I am all ears. Code is as follows:
using UnityEngine;
using System.Collections;
public class RotorRPM : MonoBehaviour
{
private float totalRotation = 0;
public int NumberofRotations
{
get
{
return ((int)totalRotation) / 360;
}
}
public static int rotations;
private Vector3 currentEuler;
private Vector3 lastPoint;
private int LastNumberofRotations;
// Use this for initialization
void Start()
{
lastPoint = transform.TransformDirection(Vector3.forward);
lastPoint.y = 0;
LastNumberofRotations = 0;
}
// Update is called once per frame
void Update()
{
NumberOfRevolutions();
rotations = NumberofRotations;
}
void NumberOfRevolutions()
{
Vector3 facing = transform.TransformDirection(Vector3.forward);
facing.y = 0;
float angle = Vector3.Angle(lastPoint, facing);
if (Vector3.Cross(lastPoint, facing).y < 0)
angle *= 1;
totalRotation += angle;
lastPoint = facing;
}
}