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 Sruit A.Suk · Jul 29, 2014 at 04:15 PM · rotationjavascriptmeshlookatmeshcollider

How to find the lookat Position of this Mesh Collider?

Hello,

I want to put a lot of "textures" (eg. spray, blood) in to mesh collider

I want to put at at the position that user click (no exact position) at it (I use ScreenPointToRay to do this, so I already get the exact point of the Mesh Collider from my click at screen (name as sprayFar in below) )

this is the image to explain what the rotation I actually want

alt text

currently, I put texture in ( plane , sprite object) and generate it over the Mesh Collider

but now I can only place at the exact position, but can't rotate it to the proper rotation (I want it to rotation of lookout of its face)

ps. I already try something like this ScreenPointToRay(Input.mousePosition), out ray) {

// this one have rotation as default, so it's face always look to the front Instantiate (sprayFar, ray.point, Quaternion.LookRotation(ray.point) );

// this one have rotation as lookat from mouse position so the plane will flip and you can see only its hip (also, rotation of the mouse position to the point also not the proper one) nstantiate (sprayFar, ray.point, Quaternion.FromToRotation(sprayFar.position, ray.point) );

// this one have rotation as lookat from The Mesh Collider point to mouse position, so it's just be able to flip their face to show (however, rotation not the proper again) Instantiate (sprayFar, ray.point, Quaternion.FromToRotation(ray.point, sprayFar.position) );

// this one also not the proper one Instantiate (sprayFar, ray.point, ray.transform.rotation);

}

I'm just start using unity only 1 weeks, so, if you would like to suggest, please, please please please write the exact function name or exact feature name :D

  • I don't know is it has any better way to get it, if you have any better way, please feel free to teach me ! (I also think, it must have the better way than this) **

something like if it can put as materiel, texture in game/script and exact position, please tell me

Thanks!

b.png (208.1 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 robertbu · Jul 29, 2014 at 04:51 PM

Your code fragments don't make sense to me. What you are trying to do has been covered a number of time on Unity Answers. How you do the rotation will depend on what kind of object you are using to display your blood. The process works as follows:

  • Construct a ray from the mouse position.

  • Cast that ray using either Physics.Raycast() or for a specific collider, Collider.Raycast(). Use a form of Raycast that takes a RaycastHit as a parameter.

  • Align the object to display the blood with the RaycastHit.normal.

A Unity Quad is often used for this purpose. The back side of the Quad displays the texture, so the position and rotation code might look like:

 blood.transform.position = hit.point + hit.normal * 0.01;  // Place blood a bit above mesh
 blood.transform.rotation = Quaternion.FromToRotation(-blood.transform.forward, hit.normal) * blood.transform.rotation;

'blood' is a reference to a Quad with a blood texture.

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

2 People are following this question.

avatar image avatar image

Related Questions

How to rotate a mesh collider? 0 Answers

how to limit axis of rotation when looking to a target 1 Answer

How to rotate slowly and look at a target On Click (mouseUp) 1 Answer

Problem when creating UVs coordinates 1 Answer

How to achieve a rotation on "batch quads" ? 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