Search Unity

How to directly stop 2 pieces moving when they collide?

Discussion in 'Scripting' started by celaeno, Jun 20, 2013.

  1. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    64
    Hello,

    I'm making a puzzle sliding game and now I'd like to make a piece stop moving when it hits another piece. Now, when i set all the rigidbodys to FreezeAll, there is no collision anymore, pieces go through each other as if they are not there. Is this a bug, or am I doing something wrong?

    What I'd like to achieve is to make 2 pieces directly stop moving when they collide. Is this the right way or should I do someting else?

    Thanks
     
    Last edited: Jun 20, 2013
  2. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    You can set the velocity to 0,0,0 and stop it in its tracks.
     
  3. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    64
    Thanks,

    but this might only work right after a collision. What i;d like to do is make an immovable object. Like a constant force to a wall and the wall won't move. I thought FreezeAll would work?

    So that when you slide a piece of the puzzle, that it will stop when colliding with another piece, while you are still trying to drag the piece throught the other piece.
     
    Last edited: Jun 20, 2013
  4. BlackMantis

    BlackMantis

    Joined:
    Feb 7, 2010
    Posts:
    1,475
    have you thought of creating a set of points for the pieces to lerp to so they always stay square to the other pieces? Almost like a grid. I came across a one liner not long ago that locks the transforms in a grid, so if you slide it or move it however it stays within the set units apart.
     
  5. celaeno

    celaeno

    Joined:
    Jan 31, 2013
    Posts:
    64
    Thanks, I'm porting this game to Unity and this is how i did do it before, but then you have to keep track of the positions of the pieces, I thought it should be easier done in Unity. But why doesn't FreezeAll work? When freezing rotation and position one by one it stops moving or rotating in those directions after a collision, but when you turn on all the constraints, then there is no more collision. I was wondering if this is a bug?