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

How to make an object impassable?

Discussion in '2D' started by Slabada, Feb 10, 2022.

  1. Slabada

    Slabada

    Joined:
    May 2, 2021
    Posts:
    50
    Hello, there is a player and a wall, both weigh BoxCollider2D and Rigidbody 2D(kinematic), in theory, the player should not pass through the wall, but he passes, how to cope with it?
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    Kinematic doesn't have a collision response, it doesn't respond to forces. That's the whole point of a Kinematic body.
     
    Slabada likes this.
  3. Slabada

    Slabada

    Joined:
    May 2, 2021
    Posts:
    50
    Can you tell me how to make a wall a wall? so that it would be impossible to pass through it
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,507
    This is such a basic question I have to suggest that you follow a starter tutorial on Unity Learn for 2D physics such as this one here.

    It's not about a wall, it's about something that doesn't pass through a wall. This, of course, depends on what you're using for your "player". Typically that's a Rigidbody2D set to Dynamic body-type. Dynamic body-mode has a collision response (bouncing, friction etc) as well as stopping overaps or resolving them.

    Things that don't move are Static so either add a Rigidbody2D and set its body-type to Static or don't add a Rigidbody2D (just the Collider2D) and they are implicitly Static so won't move and, like everything else, cannot move because you should never modify the Transform.

    The question back to you is, how are you moving the "player".
     
    Slabada likes this.