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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Collision in a top-down game

Discussion in 'Physics' started by ogsaa, Jul 19, 2015.

  1. ogsaa

    ogsaa

    Joined:
    Jul 18, 2015
    Posts:
    5
    I'm trying to create a top-down game in Unity. I have two objects (planes), each with a Box Collider and Rigidbody components. One of the planes is the player, the other is a building:

    Capture.PNG

    I set "Is Kinematic" to true for the building's Rigidbody so that it doesn't move when the player runs into it. The problem is that it's possible for the player to slip through the building by rotating around a bit and running into it:

    physics.gif

    Both the player and the building are at a Y position of 1, and both are 10x1x10 (XYZ). I also froze the Y position of the player's Rigidbody, because otherwise it would fly upwards after hitting the wall.

    What am I doing wrong? Is there a better way to model collisions in "2D" top-down games like this?

    Oh, and I'm not using the 2D editor, because I want to use Unity's nav mesh stuff.

    Cheers.
     
  2. ogsaa

    ogsaa

    Joined:
    Jul 18, 2015
    Posts:
    5
    I tried giving the building's Box Collider a bigger height and it seems to have fixed it, but I'm not sure if this is the correct solution - my only experience with physics engines is with Box2D where you don't need to worry about the Y (Z) axis.
     
  3. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Look at it while the game is running, if it has a rigidbody, and it's not frozen (by checking the freeze rotation and position checkboxes), maybe it slid up. Or maybe the player is in the ground.
     
  4. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    And btw, there's a way to use 2d navmesh, there are plenty of videos about it: