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
0
Question by VividRedemption · Jul 12, 2014 at 05:36 PM · raycastboundsedge detection

Find closest edge of mesh renderer from raycasthit

I've been working on making my decal system a little smarter, and resizing or cutting off decals that are too close to the edge of the renderer. But I've been having a lot of trouble trying to get the distance of the raycasthit to the edge of the renderer. I've looked at collider.bounds, but that doesn't give me where the raycast hit, or the distance. Here's an image to illustrate better.

alt text

Any help is very appreciated!

screen shot 2014-07-12 at 11.01.01 am.png (123.3 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MakeCodeNow · Jul 12, 2014 at 05:48 PM

It's been a while since I've done this, but I can think of two options. In both cases, you need to know which triangle of the mesh you are on.

1) Compute the barycentric coordinates of the point in the triangle. Find the smallest component to get the nearest edge.

2) Project the point onto each edge. Check the distance between the original point and projected point. Smallest distance gives you the closest edge.

However, for a decal system specifically, most edges are fine. You need to find the closest edge and then determine if it's a "visible" edge, which usually means doing a dot product of the face normal for the two tris that share the edge and seeing if they are greater than some number.

Note that there are a lot of good articles and books that talk about good decal systems, clipping, and mesh acceleration structures. I definitely recommend doing some research if you want to make a really great decal system. Or just buy one of the ones from the asset store :)

Comment
Add comment · Show 2 · 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 VividRedemption · Jul 13, 2014 at 05:48 AM 0
Share

Thanks, this is helping a lot, now I'm trying to figure out the Vector3.Dot. I'm not sure what to feed it for the two vector3's. One would be my hit.transform I would imagine, and that gets the rotation of the object I hit, how do I get the rotation of the face next to it?

avatar image MakeCodeNow · Jul 13, 2014 at 02:14 PM 0
Share

Dot the face normal of each tri, which is what I said in my original answer :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Get closest point on collider on at a certain z depth 0 Answers

Checking if ground is 'level' 1 Answer

how to find the width of a parent gameobject without using bounds? 1 Answer

Can I use a raycast to retrieve information from the collider? 2 Answers

Simple example bound box or get the top position gameobject 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