- Home /
How do I use raycasts to see coordinates of the hit?
I want to click on a plane, and get the coordinates of the point on the plane that I clicked.
Take a look at the Barycentric Coordinates. Alternatively you can just use the Point parameter and calculate it yourself, knowing the size of the plane, it's orientation, and it's position in the world.
Answer by whydoidoit · Jul 12, 2012 at 09:49 AM
If you are using Unity Script then you can do it like this:
var hit : RaycastHit;
if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), hit, 1000) {
var localHit = transform.InverseTransformPoint(hit.point);
//Do something with the local coordinates
}
This will give you the hit point in terms of the plane's coordinate system.
You know, I never use InverseTransform. I should start using it.
Answer by senad · Jul 12, 2012 at 09:34 AM
You need to do a regular ray cast. This will give you the position on the plane you clicked on with your mouse in world coordinates.
You can also use
Camera.main.ScreenPointToRay()
like here:
http://answers.unity3d.com/questions/13577/using-raycast-to-get-mouse-input.html
Your answer
Follow this Question
Related Questions
Character Customization Problem, Hard to explain... JS 0 Answers
Unity UI click through problem ( seems to be a common problem :( ) 0 Answers
Positioning a instantiated object using Input.Mouseposition doesn't position right? 1 Answer
mouse position seems to be the same everytime 1 Answer
Click Position 1 Answer