How to find the lookat Position of this Mesh Collider?


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

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)

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 :smiley: ***

** 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 ***


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.