Search Unity

Prevent moving rigidbody while standing on it

Discussion in '2D' started by holodok, May 27, 2015.

  1. holodok

    holodok

    Joined:
    May 27, 2015
    Posts:
    2
    I'm developing a game where the hero can move blocks. The problem is that when hero is standing on the block, he can move it as well.
    The block has a rigidbody2d and collider2d attached to it. The hero also has a rigidbody2d and collider2d.
    The picture shows how the hero should be able to move the block and how he should NOT be able.

    Thank you for any help.
     

    Attached Files:

  2. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    It seems that unlike the real world, there's no preservation of momentum in game physics i.e. no opposite reaction that would, in your case, neutralize the forward motion.

    Therefore, I can only offer some sort of work around. (Like if the player is resting on something other than the block).

    Perhaps, my colleagues who are expert in physics may suggest something more physically correct...
     
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I'm not a coder - but it seems the easiest way to set this up would be to only allow the character to push the blocks if he is grounded - or on the ground Y plane.
     
  4. Gardes

    Gardes

    Joined:
    Apr 7, 2015
    Posts:
    46
    My solution would be: Make the block Kinematic, add a Trigger just there where he is allowed to move and move it via script
     

    Attached Files:

    Leo-Yaik and theANMATOR2b like this.
  5. holodok

    holodok

    Joined:
    May 27, 2015
    Posts:
    2
    Gardes likes this.