© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
16 replies
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 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);
    }
    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);
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Tag helper not working properly
C#CC# / help
12mo ago
Blazor StateHasChanged not working properly?
C#CC# / help
2y ago
[ASP.NET] Docker build not working properly.
C#CC# / help
2y ago
❔ Role Based Authorization is not working properly.
C#CC# / help
3y ago