move objects to a specific position relative to the player

Hi, I’m developing a game where you can command a group of soldiers and I’m finding it difficult to move them in formation in front of the player.
I am using this function to derive the position that each soldier should assume in a specific formation

Vector3 CalcPosition(int index, int columns) 
    {
        float posX = (index % columns) * space;
        float posZ = (index / columns) * space;
        Vector3 ret= transform.InverseTransformPoint(new Vector3(posX, transform.position.y, posZ+1));
        
        return ret;
    }

and i’m using MoveTowards to move soldiers from the position where they are to the position computed.

Unfortunately does not work, does anyone know how to do that?

I guess your problem is that you got lost in the various InverseTransformX functions.

what you probably need for your current situation is to change your current code to the following:

 Vector3 CalcPosition(int index, int columns) 
     {
         float posX = (index % columns) * space;
         float posZ = (index / columns) * space;
         Vector3 ret= transform.InverseTransformVector(new Vector3(posX, 0, posZ + 1));
         
         return transform.position + ret;
     }

this will create the vector as a base from origin to an imaginary position if your character stood in the origin with no rotation.

Then we apply the players rotation by InverseTransfromVector

Then we can add the players position as offset.

Let me know if that was the issue.