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

2D Top down game collider question

Discussion in '2D' started by _jacks, Aug 20, 2015.

  1. _jacks

    _jacks

    Joined:
    Nov 27, 2014
    Posts:
    27
    Hello

    I have a top down 2D rpg style game I'm developing and I've implemented player movement, which is working fine but I'm not sure how to implement the colliders properly because of the top down style.

    So you can image an house which has a box collider 2d on it and the player has a box collider on it, when the player transform position moves and collides with the collider 2d on the house it should stop player movement but instead it does strange things like rotate the map on the Z axis

    Anyway I was hoping there was a solution to this that someone knows of perhaps a different way to solve this issue. I would like to define areas that are either out of bounds or that the player is unable to enter for objects like houses, rocks, cliffs, etc

    Thanks
    Jack
     
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Does the house have a rigid body on it? If so you could take it off or make it kinematic
     
  3. _jacks

    _jacks

    Joined:
    Nov 27, 2014
    Posts:
    27
    If I put a rigidbody2d on the house and it's kinematic the player walks through the house without being stopped. if i make turn off kinematic it collides but moves the house like it's pushing a ball or something around.

    I've tried messing around with the mass of the house and stuff but I can't get it to behave how it should. Any other suggestions?
     
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    You could try setting the position in the rigid body constraints
     
  5. _jacks

    _jacks

    Joined:
    Nov 27, 2014
    Posts:
    27
    I've set the constrains on X,Y but it rotates on the Z axis.

    If I set the Z rotation constraints it says in Unity "Rather than turning on all constraints, you may want to consider removing the Rigidbody2d component which makes any colliders static. This gives far better performance overall"

    Regardless if I turn on all constraints, the player just walks through the collider.
     
  6. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    The collider isn't a trigger?

    So if you take the rigid body off you have the sprite & a box collider (not a trigger) & the players collider isn't a trigger either yet the house moves when you walk into it? Have you tried adding layers & setting them to react to each other?

    Have you checked the video tutorials for help? The collides work the same way whether it's top down or side on. I don't have access to my 2d stuff but I haven't had this issue before
     
  7. _jacks

    _jacks

    Joined:
    Nov 27, 2014
    Posts:
    27
    I'll try with the layers and let you know. Thanks
     
  8. _jacks

    _jacks

    Joined:
    Nov 27, 2014
    Posts:
    27
    My solution was to leave the colliders on static objects with no rigidbody 2d on them, and have the dynamic player object have a rigidbody 2d but freeze the Z axis constraints

    Thanks