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 dchen05 · Jun 19, 2013 at 12:37 AM · mathverticeslinepolygonintersect

Detect where line intersects outline shape

I am trying to calculate the width of the limbs on my procedurally generated 2D character.

I need to find the two points circled in red here alt text

I have the character mesh as the mesh you see above, a mesh collider, and also just the outline shape.

The lines originate from inside the mesh so I think a raycast and collision wouldn't quite work.

I would think I need to use the outline shape and loop through all the outline vertices (there are many), until I find the segment of the outline that my white line intersects.

Does anyone have any help they could offer or have a better idea?

twopointsonoutline.jpg (63.9 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
2

Answer by robertbu · Jun 19, 2013 at 01:33 AM

Here are a couple of untested ideas:

Idea 1: Make the white vector v3Dir, and the point in the center of the sphere as v3Pos. To get the width, you follow the vector out a distance you know is beyond the character, and raycast back to the center. You do this for both sides and then you can measure the distance between the two hit points.

 var hit : RaycastHit;
 var v3CastPoint = v3Pos +
 var ray = new Ray(v3CastPoint, -v3Dir,)
 collider.Raycast(ray,  hit, someLongDisance);
 var v3Pt1 = hit.point;
 
 v3CastPoint = v3Pos -  v3Dir.normalized * someLongDistance; 
 ray = new Ray(v3CastPoint, -v3Dir,);
 collider.Raycast(ray,  hit, someLongDisance);
 var v3Pt2 = hit.point;
 
 var width = (v3Pt1 - v3Pt2).magnitude;

'collider' is the collider of the character.

Idea #2: I don't understand how your character mesh is constructed. But if your triangles you are using for the mesh span the width of the character, you can take go above your character and raycast down to the center of the sphere. The RaycastHit will include a reference to the triangle hit. From there you can get the three vertices that makeup that triangle. From these vertices you can get an approximate width.

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

14 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

Related Questions

Wireframe Shader With Shared Lines Removed 0 Answers

Vertex count 10 times higher in Unity 5 Answers

how to: create a four vertex, two tri square polygon in Unity Editor or Script? 4 Answers

How to determine if a line intersects with a frustum 2 Answers

Creating a polygon from a set of paired Vector3s 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