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 /
avatar image
2
Question by zeiteisen · Oct 30, 2010 at 10:32 PM · raycastcubehitside

Detemine wich side of a cube was hit

I do a raycast an use the point attribute from RaycastHit.point to call a function

private string HitSide(Vector3 point) { string side = "none"; if (Physics.Raycast(point, Vector3.down, 1.0f)) side = "top"; else if (Physics.Raycast(point, Vector3.up, 1.0f)) side = "bottom"; else if (Physics.Raycast(point, Vector3.forward, 1.0f)) side = "front"; else if (Physics.Raycast(point, Vector3.left, 1.0f)) side = "right"; else if (Physics.Raycast(point, Vector3.right, 1.0f)) side = "left";

 return side;

}

unfortunately it returns always "top". I think the approach is wrong. Has someone a idea how to determine wich side of a cube was hit?

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
4
Best Answer

Answer by Tobbe Olsson · Oct 30, 2010 at 11:51 PM

I always go about these things the simplest way I can, I guess it's because I'm from an artist background.

I would personally set six empty game objects as children of the cube, have no collider on the cube and create six colliders that are aligned to each side of the cube. Then you can do whatever you want when each side of the cube is hit.

I imagine that would be cheaper on the CPU than raycasting?

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 Pashkova · Aug 08, 2016 at 09:00 AM 0
Share

Woow, you're a genius, i was going to calculate a dot product between the camera direction and cube's face normal, or at least check the rotation when of all the faces are up... but this is simple and smart! Well done!

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

1 Person is following this question.

avatar image

Related Questions

default cylinder to indicate hit.normal 1 Answer

Particle Instantiation problem. 0 Answers

Is object at least partly visible? 1 Answer

Object Reference not set to an instance of an object only appears occasionally? 1 Answer

Detect Object that are hit by a ray 3 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