Search Unity

Forcing physics to ignore 3rd dimension

Discussion in 'Editor & General Support' started by jocoUnity, Jan 23, 2012.

  1. jocoUnity

    jocoUnity

    Joined:
    Oct 2, 2011
    Posts:
    25
    Working on a top down 2d game with lots of 2d and 3d physics collisions happening.

    Imagine playing cards being moved around on a table. Many will overlap bumping "up" into the 3rd dimension.

    This large amount of collisions (large number of objects) is bring the simulation on the iPad down to it's knees.

    Is there anyway to force the physics engine to ignore any calculations for the 3rd dimension?

    The goal is (from the example above) that the cards would never over lap but just have their edges bump against each other.

    Hope that makes sense. Thanks.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Use rigidbody constraints, where you would use freeze position Y, and freeze rotation X and Z. I doubt that would have much effect on the framerate though.

    --Eric
     
  3. Johnny-Photon

    Johnny-Photon

    Joined:
    Sep 4, 2011
    Posts:
    84
    How are you "dispensing" the cards? You could write your own collision detection. One way to do this (the obvious way) is to check the moving card's edges against all the edges of the existing cards. The other way is to create a 2D array representing all the cards on the table. You start by clearing all the values to zero. Each time a card is placed you set all the values of the area of the card to 1. Now when the next card is dealt you check the area the card is moving into. If it's non-zero, the card stops.

    I'm not sure I understand what you are doing enough to help.
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Sounds to me you actually want playing cards to not collide with each other, is that right? if so then you need to set up your collision layers: http://unity3d.com/support/documentation/Components/Layer Based Collision detection.html

    Physics speed gains:

    1. clever use of layers to minimise what kind of objects bother checking others (http://unity3d.com/support/documentation/Components/Layer Based Collision detection.html)

    2. lower your iteration solver count (http://unity3d.com/support/documentation/Components/class-PhysicsManager.html)

    3. lower the framerate of fixedupdate (http://unity3d.com/support/documentation/Components/class-TimeManager.html)

    Calculate this by 1.0/30 for setting the rate to 30fps. Turn on Interpolation for all rigidbodies so it looks smooth regardless of physics update rate.
     
    Last edited: Jan 24, 2012