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 DiscoFever · Sep 23, 2015 at 11:38 AM · physics2dkinematic

[2D] Tetris game with rigidbodies snapping bug

Hi,

I'm making a quick tetris clone; i made the blocks fall by giving them a rigid body and forcing to constraint on the x axis but whatever I do; i still end up having edge snapping and other weird actions.

     float number = transform.position.x;
     float _x = (float)Mathf.Round(number *) / 2;
     transform.position = new Vector3 (_x, transform.position.y);

Even tried to 'snap' the x position to the nearest half value but i still have problems.

I'm afraid that if i use kinematic; i won't be able to handle collisions (with other blocks or ground)

Any ideas here ? (I don't want the blocks to move 1 unit by 1 unit, but pixel by pixel instead)

Thansk

Comment
Add comment · Show 5
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
avatar image Hellium · Sep 23, 2015 at 11:38 AM 1
Share

Another and (maybe cleaner way to do this), is not to rely on collisions detections with rigidbodies, but creating a workaround using raycasts.

When instantiated or move, the block casts a ray downwards. According to the y position of the impact point, you know your block must not go below this limit.

avatar image DiscoFever Hellium · Sep 23, 2015 at 12:16 PM 0
Share

Thanks for the reply; i've thought of this alternative too; but I imagine having, i don't know, a hundred of blocks raycasting every frame can be very costly especially on mobile; it's ok for a platformer since you have only a few objects ...

$$anonymous$$mmh any other idea ?

avatar image Hellium DiscoFever · Sep 23, 2015 at 12:30 PM 0
Share

I have never said you had to raycast every frame, only when the block is instantiated or when moving horizontally

Show more comments
avatar image mujpir · Sep 24, 2015 at 08:07 AM 0
Share

I think making a tetris game by physic collision detection is not a good idea . I have made several tetris games in unity . Actually every game studio that I've worked at asked me to build a tetris game for them .

So , I highly recommend you to avoid physics because you have no control for your blocks as you have already encounter one of them.Ins$$anonymous$$d create a 2d array of cells that your block can move through them . This way you have more control over your blocks . Every frame you can check if your blocks can move down further by checking next down cell to see if it occupied by other block or not ? If it's free your blocks can continue moving down . Also you can smooth your blocks movement , They have not to move 1 by 1 unit . lerp the position of them until they reach other cell .

I hope it can help you.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I Spawn an Object on a Seafloor Randomly? 0 Answers

Detect Contact between Kinematic and Non-kinematic bodies 1 Answer

2D physics, animation-controlled kinematic colliders not affecting momentum 1 Answer

How to check for collision between a moving kinematic object and an empty object? 3 Answers

The character velocity changes while the rigidbody is kinematic 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