• 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 Rush3fan · Jul 12, 2012 at 06:10 AM · forceuv

Force in direction of triangle's UV forward vector?

Ok, so read carefully: I've been wanting to make a mesh force other rigidbodies in the direction of it's triangle UV. So, for example, you have one mesh that has a series of planes with textures that resemble conveyor belts. You would be able to aim the force that the conveyor belt produces by mapping the texture in your modeler. My question is how do you find the triangle's uv transform.forward vector that the rigidbody collided with?

I know this is a bit confusing, but the idea could help me out enormously.

Comment
Add comment · Show 2
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 Rush3fan · Jul 12, 2012 at 07:44 AM 0
Share

I suppose I would have to find the nearest triangle using squared magnitude from the contact point of the rigidbody that collided with the mesh. So, that brings me to a new question is how to iterate through the triangles of a mesh and create a rotation vector from that triangle's uv coords.

avatar image whydoidoit · Jul 12, 2012 at 08:46 AM 0
Share

So what you want is a vector that points in the direction of the UV mapping of the triangle you found? As in it points from 0,0 to 1,1 or something along the surface of the triangle?

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by whydoidoit · Jul 12, 2012 at 09:09 AM

So I think the easiest way to find the force direction in terms of the triangle is to actually raycast to get the triangleIndex when you hit the collider - that only works when the thing you hit is a MeshCollider though - and they are rather slow and liable to backface culling which could cause you problems. Otherwise you could simulate a ray cast by taking a line from your object in the direction of -transform.up and test it against all of the triangles in your mesh.

Once you have the triangle index then you are going to want to decide on the vector you want in terms of UV. Say from (0,0) to (1,0) for a horizontal then you are going to need the three UV coordinates of the points of the hit triangle and decide the direction which changes U but not V (I'm struggling to be sure that this is always possible). I'm guessing you just take point 1's V and then solve the equation of the opposite line (point 2 to point3) for that value of V which now gives you a second point. The force direction would be the line connecting point 1 and the found point on the line from point 2 to point 3.

With a triangle index it is trivial to find the UV of each of the points - use the triangles array, multiply your triangleIndex by 3 and select the UVs for the three indicies found there.

Comment
Add comment · Show 9 · 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 whydoidoit · Jul 12, 2012 at 09:23 AM 0
Share

On reflection if there is no solution to p2 - p3 for the same V then the force for a horizontal line is directed down p2 - p3.

avatar image Rush3fan · Jul 14, 2012 at 07:54 PM 0
Share

Thanks! This sounds understandable. I just need to find out how to capture uv info and then the vector math doesn't seem like it'd be so hard. I'll try the raycast and see if I can't access the triangle index. If it wouldn't be too much to ask, could you give me links to whatever script functions I'll need to be looking at in order to capture triangle index and then uv?

avatar image whydoidoit · Jul 14, 2012 at 08:05 PM 1
Share

Sure do a Raycast and get the RaycastHit which contains the triangle index on the mesh collider that you hit.

Now look at this documentation of triangleIndex and you will see the example extracts information about the vertices - in your case you want to use the 3 uvs in addition to the vertices but the technique is the same.

Then you are going to be solving the equation for the lines and plugging the results back in.

avatar image Rush3fan · Jul 14, 2012 at 08:10 PM 0
Share

Ok.. You make it sound so easy. I'll give it a go then. Thanks for the help!

avatar image Rush3fan · Jul 14, 2012 at 08:12 PM 0
Share

Perfect! The links are very helpful!

Show more comments
avatar image
1

Answer by The-Arc-Games · Jul 12, 2012 at 08:13 AM

There's a technical obstacle with your request. UVS are bi-dimensional, so there actually no 'forward', for them, but only normalized x and y, relative to the 0-0 corner and 1-1 corner coordinates of the texture.

What you need to do is certainly create a meta data structure, where you assign one 'forward' to each interested triangle, or set of triangles, based on a rule that you must implement.

Triangles can be accessed through the mesh component of any model.

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 Rush3fan · Jul 14, 2012 at 07:57 PM 0
Share

Thanks for the link Arc Games. It's obvious I don't know who has the best answer at this point, but I'm sure both will help.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a conveyor belt? 6 Answers

Hi, I was wondering how to set up a conveyor belt in Unity. 0 Answers

Assigning UV Map to model at runtime 0 Answers

Animation with UV Warp Modifier from Blender 2 Answers

Send Custom Network Message Unity Multiplayer 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