C#C
C#3y ago
Velcer

❔ Flip Board not working properly

Hello, I'm working on a level editor for my game. My board is not flipping properly.
I've attached a video.
Here is my code:
        public void FlipBoard() 
        {
            foreach (var boardObject in _placedObjects)
            {
                if (boardObject.buildable.Category == LevelEditorCategory.BoardTile || boardObject.buildable.Category == LevelEditorCategory.Piece || boardObject.buildable.Category == LevelEditorCategory.ActionTile)
                {
                    var pos = boardObject.Position;
                    var newRotation = new Vector2(pos.x, pos.y);


                    newRotation = newRotation.Rotate(180);
                    newRotation.x += _levelBounds.max.x;
                    newRotation.y += _levelBounds.max.y;
                    



                    boardObject.transform.position = newRotation;
                    boardObject.Position = new Vector2Int((int)newRotation.x, (int)newRotation.y);
                }

            }


            isFlipped = !isFlipped;
        }



    public static Vector2 Rotate(this Vector2 v, float degrees)
    {
        return v.RotateRadians(degrees * Mathf.Deg2Rad);
    }

    public static Vector2 RotateRadians(this Vector2 v, float radians)
    {
        var ca = Mathf.Cos(radians);
        var sa = Mathf.Sin(radians);
        return new Vector2(ca * v.x - sa * v.y, sa * v.x + ca * v.y);
    }
Was this page helpful?