Orbit while facing 90 degrees - Efficiency

Hi guys,

I’m trying to orbit ships around a planet while keeping them facing at 90 degrees. I have this working for the most part but find as the number of ships increases, I’m losing FPS due to the rotation method.

2910133--214541--upload_2017-1-6_16-33-58.png

Each ship is moving forward a constant velocity. The rotation method I’m currently using is:

    public void Rotate90degs()
    {
        Vector3 diff = planet.transform.position - transform.position;
        float rot_z = (Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg) /* -90 */;
        Quaternion newRot = Quaternion.Euler(new Vector3(0,0,rot_z));
        transform.rotation = Quaternion.RotateTowards(transform.rotation, newRot, Time.deltaTime * 75f);  
    }

I know I can make them childs of a rotating game object, but that’s not really going to suit my purposes for this.

Any other suggestions on a more efficient way to do this?

It might be faster to do this:

    public void Rotate90degs()
    {
        Vector3 diff = planet.transform.position - transform.position;
        transform.right = diff;
    }

Which transform.* you need to use will depend on the direction your ships have from the start. There is; transform.up and transform.right available and to get down and left you just use those available and change the direction of your diff-vector, that is you use -diff.

1 Like

Thanks PGJ, that definitely helped!