- Home /
raycast hit to relative location on collider?
This is the code I'm currently using:
if(Input.GetMouseButtonUp(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); int mask = ~(1 << 8); RaycastHit[] col = Physics.RaycastAll(ray, 100f); foreach(RaycastHit info in col) { GameObject hit = info.collider.transform.root.gameObject; Debug.Log ("hit" + hit); if(hit.name.ToLower() == "texture") { Debug.Log("hit texture"); } } }
What I want to do... is find the location on the plane I hit with the raycast. I need to know if I'm clicking towards the middle of the plane, or towards an edge.
So, If the ray hits a gameObject with the name "texture", I want to see where on that gameObject the ray actually hit relative to the gameObject's locations. This is strictly dealing with planes.
format your code with the "101010" button, please. This way is illegible.
Answer by whydoidoit · Sep 30, 2012 at 10:52 PM
You can use the point in the RaycastHit and use InverseTransformPoint on the transform of the hit collider to get it in local coordinates if that's what you need.
Your answer
Follow this Question
Related Questions
How to hit two object with one raycast? 2 Answers
Raycast visual and moving text possition. 1 Answer
How to hit two objects with only one shot (raycast) 0 Answers
how to check if 1 sided plane is facing the camera 1 Answer
How to use a Raycast to see the distance traveled within a collider. 2 Answers