Search Unity

Make Player, Enemy and terrain collide without pushing

Discussion in 'Physics' started by MatheusCohen, Feb 10, 2019.

  1. MatheusCohen

    MatheusCohen

    Joined:
    Aug 24, 2017
    Posts:
    57
    I searched thourgh this forum and some others regarding this questions but couldn't find a good answer:

    I have 3 different kinds of "entity" in my project: The Player, Npc/Monsters and terrain.

    the terrain is made with tilemap, so it's using rigidbody2D(static) and composite.

    My problem is, i need all 3 types to "wall" each other, as in:

    1 - A Player can't push or pass through a enemy nor terrain.
    2- A enemy/Npc can't push or pass through other enemy's(they should not be able to stack on the same space), Player or terrain.
    3- Terrain can't allow any Player or Npc/Enemy pass.

    I tried a few interactions, but none worked.

    - If player is Dynamic and enemy Kinematic, terrain let enemy pass, Player can't move enemy(good) but enemies can push player. Enemies can stack up.

    - if player is Kinematic and enemy Dynamic, terrain let player pass, enemies can't push player...but Player can push enemies. Enemies can't stack up(good).

    i'm aware that there maybe some solutions using triggers and changing the enemy/player/terrain behaviour, but i can't come up with a good way to solve this.

    any suggestions?


    i may try to change the movement behaviour of my player to use transform instead of rigidbody, and keep the rigidbody only to work through collisions(Dynamic and to set constraints at X and Y).
    if i tested correctly, this way enemies can't move him, enemies won't move thourgh terrain and won't stack up. but i feel this is some kind of solution that may give me either problems down the line or performance issues.

    EDIT:
    after a few more tests, this didn't work :p
    not sure why, but placing your dynamic rigidbody with constrains on X and Y turn's it into static?(i understand the "behaviour" is the same if they won't move, but still..)
     
    Last edited: Feb 10, 2019
  2. JesterGameCraft

    JesterGameCraft

    Joined:
    Feb 26, 2013
    Posts:
    452
    Perhaps the Physics Collision Matrix in Project Settings->Physics could help you.
     
  3. bingofly

    bingofly

    Joined:
    Sep 15, 2018
    Posts:
    27
    @MatheusCohen

    Have the same problem with you, have you find any solution?
     
  4. MatheusCohen

    MatheusCohen

    Joined:
    Aug 24, 2017
    Posts:
    57
    Hi!

    the solutions i found were:
    -Change the collision/RB types dinamically based on some parameters(either by raycast/collision/etc)
    -Make a custom solution without using the standard collision methods
    -Accept the unwanted collisions and implement them

    I end up accepting the collisions...just increased the mass of my character so it would drag slowly :)
     
  5. bingofly

    bingofly

    Joined:
    Sep 15, 2018
    Posts:
    27
    OK, fine, game develoment is about compromise. Thank you.