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 /
  • Help Room /
avatar image
0
Question by AndyB275 · Apr 25, 2018 at 03:49 AM · physics.raycasthit detection

Identifying objects in a stack

Hi all - newbie to Unity/Coding and just trying to get my head around a few things.

I'm creating an AR experience, in which the user interacts with a stack of objects, similar to a Jenga tower.

The type of interaction is dependant on what object is focused on with the camera, and also what side of said object.

I figured to start out with a raycast from the screen centre to hit one of the bricks in the Jenga-like tower:

 public float findingBrickDist = .6f;
     public float maxRayDistance = 30.0f;
     public LayerMask collisionLayerMask;
     
     
     void Start () {
         int layerIndex = LayerMask.NameToLayer ("ARGameObject");
             collisionLayerMask = 1 << layerIndex;
     }
     
 
     void Update ()
     {
 
         //use center of screen for focusing
         Vector3 center = new Vector3 (Screen.width / 2, Screen.height / 2, findingBrickDist);
 
         Ray ray = Camera.main.ScreenPointToRay (center);
         RaycastHit hit;
 
         if (Physics.Raycast (ray, out hit, maxRayDistance,collisionLayerMask) && hit.transform.tag == "brick") {
 
             Debug.Log ("Hit a Brick!");
 
         } 

The next part is a little difficult for me as I'm trying to decipher what side of the brick is being hit (ie. if it's the short side, that will trigger one interaction. If it's the long side, that will trigger another interaction).

Absolutely stumped on where to go after this. If anyone can point me in the right direction I would be greatly appreciative!

Thanks and hope you're doing well :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by vinilly · Apr 25, 2018 at 07:50 AM

Can you create an empty game object and assign colliders to the long side, and ends?

Comment
Add comment · Show 1 · 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 AndyB275 · Apr 26, 2018 at 01:14 PM 0
Share

...and child that to the game objects. Great tip and yeah that works, however that can be a tedious process when objects of varying shapes are in the works...

I'm just wondering if there's another way around this in code...if not, I'll be on the collider train for sure!

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

135 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

Related Questions

Need help with Ray casting syntax. 1 Answer

Issue with Raycast hit.distance Variables Reseting Itself 0 Answers

Problem dealing with RaycastHit.normal on collider edges 0 Answers

Raycast problem, likely a Unity bug? 0 Answers

I need to know how to spawn a prefab and then have it propelled forward as if thrown 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