Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Character pushing each other (ARG!)

Discussion in 'Physics' started by LightStriker, Jun 10, 2016.

  1. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    I'm about to give up, I tried everything and I spent days on this forum and google trying to find a solution to something that should be plain simple; make sure characters don't push each other.

    The problem;

    1) Have players, enemies, invaders, supporters and non-playing characters. Each with their own layers so they can attack and damage each other.
    2) All of them should not push each other. Even an enemy cannot push another enemy.
    3) They cannot cross each other. An enemy should collide with another enemy.

    Changing weight does nothing, there's always one lighter who get pushed.

    I tried adding a children with a larger kinematic collider... it works, but characters on the same layer cross each other.
    If I put that kinematic collider on a layer that everybody collide with, the character collide with is own children and is send flying. Any way to prevent this? Make a rigidbody ignore its children?
     
    Last edited: Jun 12, 2016
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    Just use Physics.IgnoreCollision() (there is a Physics2D version as well). It's for ignoring collisions between two specific colliders, even if they are on interacting layers. Put it in Start() for each actor.
     
    NNW6 and amirheb like this.
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    What the... How did I never saw that method after spending so much time in the Physics class?
    That sounds amazing. Testing that right away.

    EDIT: It is amazing and works perfectly! Thanks!
     
    Last edited: Jun 13, 2016
  4. omermecitoglu

    omermecitoglu

    Joined:
    Jul 24, 2017
    Posts:
    5
    wow thx! this saved my day!
     
  5. xXDarQXx

    xXDarQXx

    Joined:
    Jan 3, 2021
    Posts:
    5
    Hyblademin, you're an f-ing saint