Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NotNew · Feb 10, 2020 at 11:06 AM · collisioncollision detectioncollider2dcollision2dtiled

Can't detect colliders from Tiled

I'm currently working on a 2D-bomberman-like game.
I've created a map in Tiled for it, where I put 2 layers: one for the Grass, one for the Walls(tiles used in Walls layer have colliders that were created in Tiled, too).
I want to detect what is in the area of bomb explosion with Physics2D.OverlapBox function. So there are 3 options:
1. There's a Wall
2. There's a Block(Prefab with a BoxCollider)
3. There isn't anything.

The function is detecting Blocks properly, but it has some problems with Walls. This is the code I've created for my tests and two pictures that show how it looks like.
There's also a function for drawing a Box, but I think it's not necessary to show it.
Anybody knows how to solve this? Tags are set properly, collisions with walls work properly ( I mean, I can't go through the wall). Sorry if something is messy, I'm new to all this.

 void Update()
     {
         if (Input.GetKeyDown("e"))
         { 
             ContactFilter2D filter = new ContactFilter2D();
             Vector2 dimensionsOfBox = gameObject.GetComponent<SpriteRenderer>().bounds.size;
 
             //I cut the dimensions in a half, so it doesn't detect the Blocks/Walls next to it.
             Vector2 halfVector = Vector2.one / 2f;
             dimensionsOfBox -= halfVector;
 
             // box is above my character.
             Vector2 positionOfBox = (Vector2)transform.position + Vector2.up;
             DebugDrawBox(positionOfBox, dimensionsOfBox, 0f, Color.red, 5f);
             
 
             Collider2D[] objs = new Collider2D[1];
             bool foundBlockOrWalls = false;
             Physics2D.OverlapBox(positionOfBox, dimensionsOfBox, 0f, filter, objs);
             foreach(Collider2D collider in objs)
             {if (collider)
                 {
                     foundBlockOrWalls = collider.tag == "Walls" || collider.tag == "Block";
                     if (foundBlockOrWalls)
                     {
                         if (collider.tag == "Block") Debug.Log("There's a block above me!");
                         if (collider.tag == "Walls") Debug.Log("There's a wall above me!");
                           
                     }
                     
                 }
             }
         }
     }

alt text

unity-screenshots.png (79.8 kB)
unity-screenshot-walls.png (75.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

186 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to set collision for an object with specific collider size? 3 Answers

How do I set an object's velocity to the velocity of an object that collided with it? 0 Answers

Collision detection problem 0 Answers

Make 2D projectile collide only from the outside 1 Answer

Collision Killing CPU/FPS/Performance - Suggestions?! 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges