I need an object to orbit around a centerpoint. I have been able to do so, however the orientation on the object orbiting needs to look like it is going in a certain direction. (like a swimming fish) Currently the object is just orbiting, being pulled by the center I want it to look like its facing the direction it is rotating.
public float xSpread;
public float zSpread;
public float yOffset;
public Transform centerPoint;
public float rotSpeed;
public bool rotateClockwise;
float timer = 0;
// Update is called once per frame
void Update () {
timer += Time.deltaTime * rotSpeed;
Rotate();
}
void Rotate() {
if(rotateClockwise) {
float x = -Mathf.Cos(timer) * xSpread;
float z = Mathf.Sin(timer) * zSpread;
Vector3 pos = new Vector3(x, yOffset, z);
transform.position = pos + centerPoint.position;
} else {
float x = Mathf.Cos(timer) * xSpread;
float z = Mathf.Sin(timer) * zSpread;
Vector3 pos = new Vector3(x, yOffset, z);
transform.position = pos + centerPoint.position;
}
}