Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
  • Help Room /
avatar image
0
Question by IAmDerrick · Dec 01, 2021 at 04:05 AM · raycastunity 2dcollider2d

Overlapping colliders with Raycasting in 2D

This is the first time I've ever resorted to posting on the forum because I really wanted to figure this out for myself, but I'm stumped and its been over a week.

I'll try to keep it simple;

I'm building a 2d isometric tile based game with walls that equate to 3 blocks high. relative to my character who is maybe slightly taller than 1 block. The game is also not a traditional dungeon crawler or adventure map, it's a tight quarters map taking place in a school. Because of this, walls are often overlapping other walls and objects as well as the player. I've been trying to create a see-through-walls system using a sprite sprite mask, and a script that basically says: - Fire Raycast at Player - If hitting Player set ViewBubble to inactive - If not hitting Player (hitting wall) set it to active

When its active, the sprite mask makes whatever is in front of it invisible, and disregards stuff behind it. (At least that's the plan, right now its a little messy)

The issue I'm having is that while the Raycast is confirming that it's hitting my Player, and separately also confirming that it's hitting the Wall, it only hits the Wall collider if I deactivate or move the Players collider leading me to believe it has something to do with sorting layers perhaps?

alt text alt text

Anyone who could give me insight on this would be a godsend because I know it shouldn't be as difficult as I think it is. All I want is for the the Raycast to know which collider is in front of the other, or if that's not possible, maybe a different solution?

Code Below:

     public Camera camera;
     public GameObject target;
 
     void Update() {
         
         RaycastHit2D hit = Physics2D.Raycast(camera.transform.position, target.transform.position, Mathf.Infinity, LayerMask.GetMask("Obstructions"));
 
         if (hit.collider != null)
         {
             Debug.Log("Just smacking up on some " + hit.collider.name);
             if(hit.collider.gameObject.tag == ("ViewBubble")){
                 Debug.Log("Hitting View Bubble");
             }
             else if (hit.collider.gameObject.tag != ("ViewBubble")){
                 Debug.Log("Not hitting View Bubble");
                 
             }
         }
     }
 }


1.png (163.0 kB)
2.png (167.5 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

232 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

hit normal vector from raycast is always [-1,0], which makes slope angle 90 1 Answer

Unity 2D send out X amount of "troops" that are equal to the number I put in to a specific target with raycast or something 0 Answers

Why doesn't my box collider work? (Unity2D) 2019.2.13.f1 0 Answers

How do you make one game object follow the shape of another game object? 0 Answers

How can i store all colliders of colliders which collide with a prefab? 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