- Home /
The question is answered, right answer was accepted
How can i get the coordinates of the point on an object I click on?
Hi all,
I am new to this so I hope this question hassn't been asked before. I've tried finding it with google but no luck.
So I am trying to set the coordinates of an empty game object (a 'walkToPoint') to which my character has move when he walks.
What I would like to know is how to get the coordinates of the point on the object 'a plane' (and eventually terrain) i click on.
========================
Solved =)
========================
This is what I eventually used (for those who have the same question) :
var camera3rd : Camera;
var walkToPoint : Transform;
function OnMouseDown()
{
var hit : RaycastHit;
var ray : Ray = camera3rd.ScreenPointToRay (Input.mousePosition);
// Cast a ray, get its hit coördinates, set it to the walkToPoint
if(Physics.Raycast(ray.origin, ray.direction, hit)){walkToPoint.transform.position = hit.point;}
// Draw a Yellow colored ray
// Debug.DrawRay (ray.origin, ray.direction * 50, Color.yellow);
}
camera3rd = my 3rd person camera (the camera you are using to look with)
walkToPoint = A point in space my character has to walk to.
once you are an expert on this, here is a massive discussion on the details of the matter
http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html