Exemple #1
0
            public Vector3 GetFormationPosition(MyEntity entity)
            {
                if (entity == Leader)
                {
                    return(Target.GetPosition());
                }

                int index = Followers.IndexOf(entity);

                if (index >= 0)
                {
                    float FORMATION_SPACING = 100;

                    Vector3 leaderToTarget = Target.GetPosition() - Leader.GetPosition();
                    Matrix  matrix         = Matrix.CreateWorld(Leader.GetPosition(), leaderToTarget, Leader.WorldMatrix.Up);

                    int sideIndex = index / 2 + 1;
                    int sideSign  = index % 2 * 2 - 1;  // just -1 is left and +1 right

                    leaderToTarget.Normalize();

                    return(Leader.GetPosition() + leaderToTarget * FORMATION_FORWARD_PROJECTION + matrix.Left * sideIndex * sideSign * FORMATION_SPACING);
                }

                return(Vector3.Zero);
            }