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
  4. Dismiss Notice

Help with 2D Top Down Shooter

Discussion in '2D' started by allimos3, Aug 12, 2020.

  1. allimos3

    allimos3

    Joined:
    Jul 26, 2019
    Posts:
    3
    Hi,

    I am currently working on a 2D Top Down shooter and I am having a problem with wall colliders.

    I am using Tilemaps to create rooms and I have a collider Tilemap for the walls. Then, I have added a collider to the Feet of the player and it works fine. However, it is time to throw projectiles and I would want to use this same Wall Tilemap collider to destroy the projectiles, and I currently have an issue when the player is just below the top wall of the room. As you can see in the screenshot below, since the upper body of the player is on top of the wall, when I throw the projectile (bone) it is on top of the wall and it gets destroyed automatically.

    Is there a way to implement this without having to add more complexity? Almost all 2D top down games have this issue solved, so I suspect there is an easy way to solve it without having to add more collider layers.

    Thank you very much!

    upload_2020-8-12_20-0-10.png


    Albert
     
  2. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    Since Queries Start in Colliders doesn't work for tilemaps, the only option I can think of is doing two walls, most games must do this, since usually the bullets never hit the base of the wall, they usually are destroyed around the middle, to simulate depth.
     
    Last edited: Aug 13, 2020
  3. allimos3

    allimos3

    Joined:
    Jul 26, 2019
    Posts:
    3
    Thanks for your answer!!

    And then, I would have to do the same for all other objects in the scene? Having one collider for the feet of the characters, and one for the projectiles, right?
     
  4. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    Exactly, there's not major overhead, just some inconvenience, which can be reduced by using prefabs. Make sure to adjust the layer matrix accordingly, so that the bullet does not collide with the PlayerWall.
    https://docs.unity3d.com/Manual/LayerBasedCollision.html

    just a tip, you might also want to add a composite collider 2d to your tilemap, from your screenshot, doesnt look like you have one.
     
    Last edited: Aug 13, 2020
    allimos3 likes this.
  5. allimos3

    allimos3

    Joined:
    Jul 26, 2019
    Posts:
    3
    Thank you for solving my problem and for the extra tip! :)