Search Unity

Physics confusion - collisions and triggers

Discussion in '2D' started by ashley, Oct 10, 2015.

  1. ashley

    ashley

    Joined:
    Nov 5, 2011
    Posts:
    84
    Hi all,

    Sorry for this numpty question. I've tried to look around but not getting my head around the whole physics things.

    What I want is for my player to be able to bump into and slightly move an enemy (ie just a small push) and if they are seen by the enemy to trigger events. I can get one or the other to work, but not both.

    The player has a 2D box collider and a kinematic Rigidbody 2D
    The enemy has a 2D box collider and a kinematic Rigidbody 2D
    Enemies have a visible vision cone - a child sprite with its own polygon collider that is a trigger.

    When the player enters the vision cone it triggers the event as expected. I can't get the player and enemy to collide however, the player just goes over the top of the enemy.

    I have another enemy that is patrolling and if I set the player to not be kinematic but with a gravity scale of 0 the patrolling enemy will push the player, but when I try and replicate the settings on the first enemy it's not making a difference.

    At present I'm controlling the character with http://wiki.unity3d.com/index.php/GridMove for the purpose of prototyping but would be writing the player movement myself shortly.

    I believe it comes down to "if you're moving using x you need to use physics y" and that kind of thing but I just can't get my tiny brain around it at the moment!

    Happy to supply codes or anything else as needed.

    Thanks.
     
    Last edited: Oct 10, 2015
  2. ashley

    ashley

    Joined:
    Nov 5, 2011
    Posts:
    84
    Got the interactions working, just got a question about Physics now.

    So now the player just has a box collider while the enemies have a box collider, rigidbody (not kinematic but with 0 gravity) and their sight has a trigger polygon collider.

    The player can still be seen and can move enemies, but the problem is now it moves the enemy too much. Essentially I want a nudge and I'm getting a shove (that's the technical term, right?) Tried to use AddForce but not having any affect.

    The patrolling enemy is affecting it in the way I would like. The only difference I can think is that is moving itself and I'm applying movement and thus my force is greater?

    I should have paid more attention in physic classes!


    Oops just realised there's a whole physics forum! Please move.
     
    Last edited: Oct 10, 2015