Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by abdelrahmanka96 · Aug 29, 2018 at 01:23 PM · rotationunity 2dpolygon collider 2dpolygoncollider2d

Rotating a PolygonCollider2D does not change vertex points,PolygonCollider2D points not changing when rotating

Hello.

I'm new to unity and am trying to make the 2D game tetris as an exercise to learn how to use the engine.

Since the shapes are not exactly rectangular boxes, I decided to use the polygon collider for detecting collisions with other objects.

I read the documentation on PolygonCollider2D located here, and decided that using the "points" attribute of the collider with the bounds attribute of an empty object called GameArea that has the exact dimensions of the board the would work for me.

I set the points for each shape so that they wrap around it perfectly, then wrote the following script:

 public class Tetromino : MonoBehaviour
 {
     private PolygonCollider2D myCollider;
     private BoxCollider2D gameAreaCollider;
 
     void Start()
     {
         myCollider = GetComponent<PolygonCollider2D>();
         gameAreaCollider = GameObject.Find("GameArea").GetComponent<BoxCollider2D>();
     }
 
     void Update ()
     {
         if(!isInBounds())
         {
             Debug.LogError("OUT OF BOUNDS");
         }
         
         if(Input.GetKeyDown("q"))
         {
             rotateClockwise();
         }
     }
 
     void rotateClockwise()
     {
         transform.Rotate(0, 0, -90);
     }
 
     bool isInBounds()
     {
         myCollider = GetComponent<PolygonCollider2D>();
         Vector2 position = transform.position;
         foreach (Vector2 point in myCollider.points)
         {
             if(!gameAreaCollider.bounds.Contains(point + position))
             {
                 return false;
             }
         }
         return true;
     }
 }

All of the above code works visually as expected (the shape rotates successfully) however, the "points" don't change, so when part the piece is out of bounds, nothing happens.

The math needed to manually rotate the points is simple enough to do, but I want to know if there's a way to do that without having to make that calculation every time.

Thank you very much in advance!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bdiebeak · May 12, 2020 at 05:04 PM

@abdelrahmanka96

Hello!

I know that it is too late... But maybe it will help somebody else.

I think that you should use TranformPoint() for transform points of collider to world space.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

123 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Jumping Towards Orientation of the character 0 Answers

Unity2D - Lerp is rotating in 3D space instead of 2D 0 Answers

Parent/Child rotation not working 1 Answer

Rotation of the character along the axis Z 0 Answers

Bug in rotation when going to opposite quadrant 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges