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 Naggil · Sep 23, 2019 at 09:39 PM · colliderscollision detectioncollider2d

what is the best way to detect this collision?

I need a way to properly detect if the red dots box is colliding or not, in my script I have a random room generator and when it instaciates, I check wich direction is open and not with GetComponent().IsTouchingLayers() but it doesn't work was i would like, I think the problem is as the documentaction says its to slow to use as a I want, Im actually instacianting tilemaps prefabs with composite collider using a room generator gameobject with 4 childs colliders set to trigger in each direction.

alt text

the problem for example is:

 instaciate(randomcave, position, rotation); //works fine
 bool South = transform.Find("South").GetComponent<Collider2D>().IsTouchingLayers(); //returns false

but it only returns false after the instaciate if i keep cheking and printing it in the update it returns true

capturar.png (63.6 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Hannibal_Leo · Sep 24, 2019 at 02:00 AM

There are so many solutions to your problem. An easy fix would be to use Collider2D.IsTouching you know of all 4 "red dot boxes" so you can check against them. You could also use the colliders Bounds as all your tiles are rectangular. But the best way to work with a dungeon generator is to create a Grid, in code this would be represented as a 2D-Array where each tile is stored and you can declare your "red dot boxes" in the tilegrid and react on them, if you want to place a tile on one of the "red dot box"-tiles.

It depends on what you want to archive.

Comment
Add comment · Share
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
avatar image
0

Answer by Naggil · Sep 25, 2019 at 06:01 PM

well I find out a way to work around the problem using invoke, it makes the cave generation a little slow but as everythink is working now i don't need to worry, the real problem was that is.touching only take place after the physics update i just made sure that it was enough time to it update alt text now I only need to put laziness aside and finish off all the empty rooms that i was using just to code using tilemaps prefabs workout really well for me, it could be a real problem to use a script grid and spawn sprites one by one as most of my walls are just a border it would be a real pain in the ass also as im using the 2d extras assets it is really easy to instaciate objects in the tilemap (as all those stones around the map)

is there even a down side using instaciated tilemaps prefabs?


capturar.png (474.4 kB)
Comment
Add comment · Share
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

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

117 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

Related Questions

2D collision won't work? 2 Answers

Gameobject not detecting collison from other Box Collider 2D [SOLVED?] 2 Answers

2D - Two objects, each having two trigger colliders - interacting 0 Answers

Problem with method Collider2D.isTouchingLayers() 4 Answers

How come people prefer to use rays for 2d collision instead of edge colliders? 1 Answer


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