I want to make an object rotate to the saved direction of another object and it doesn’t work as expected.
CODE:
using UnityEngine;
using System.Collections;
using System.Linq;
public class TimeReflectionRotations : MonoBehaviour {
public Quaternion[] playerRotations;
public float[] playerRotationsChangeTime;
public float speed;
public float time;
public Vector3 pointToGo;
public float positionTimeNumber;
[SerializeField]private bool rotating;
private float degPerSecY;
void Start () {
}
void Update () {
if (this.transform.position != this.GetComponent<TimeReflectionPositions> ().pointToGo) {
if (time <= playerRotationsChangeTime.Last ()) {
if (playerRotationsChangeTime.Contains (time)) {
float timeToCompleteRotation = Vector3.Distance (this.transform.position, this.GetComponent<TimeReflectionPositions> ().pointToGo) / speed;
print (timeToCompleteRotation);
degPerSecY = (this.transform.rotation.y - playerRotations [System.Array.IndexOf (playerRotationsChangeTime, positionTimeNumber)].y) / timeToCompleteRotation;
print (degPerSecY);
rotating = true;
}
}
} else {
rotating = false;
}
if (rotating) {
this.transform.Rotate (0, degPerSecY * Time.deltaTime, 0);
print ("Rotate to: (0, " + degPerSecY * Time.deltaTime + ", 0)");
}
}
}
Please help me.
If you have any questions you can ask below and i’ll answer as fast as i can.
Ethan