예제 #1
0
    void Scalable()
    {
        int   numFollowers = followers.Length;
        float formRadius = .5f + (numFollowers / 8) * 1;
        float angle = 0f;
        float x = 0, y = 0;

        for (int i = 0; i < numFollowers; i++)
        {
            x = Mathf.Sin(Mathf.Deg2Rad * angle) * formRadius;
            y = Mathf.Cos(Mathf.Deg2Rad * angle) * formRadius;
            _formationSlots[i] = new Vector3(this.transform.position.x + x, this.transform.position.y + y, 0);
            angle += 360f / numFollowers;
        }
        for (int f = 0; f < numFollowers; f++)
        {
            FormationMovement followerScript = followers[f].GetComponent <FormationMovement>();
            followerScript.DoSeek(_formationSlots[f], followerScript.arriveRadius);
        }
    }
예제 #2
0
    /// <summary>
    /// Gets a direction vector relative to the direction this
    /// formation is facing.
    /// </summary>
    public Vector2Int GetDirection(FormationMovement movement)
    {
        switch (movement)
        {
        case FormationMovement.AdvanceRank:
            return(Facing);

        case FormationMovement.RetreatRank:
            return(-Facing);

        case FormationMovement.IncrementFile:
            return(Facing.Perpendicular());

        case FormationMovement.DecrementFile:
            return(-Facing.Perpendicular());

        default:
            return(Vector2Int.zero);
        }
    }