- Home /
If collider between two points get this point
Hi!
I need a bit help with Raycasts and Ray.
I got a direction, a length and start position and i want to check whether on this direction was a collider. Then return true.
If its true I'd like to get the point where it was hit.
#------------||----------------------------#
^
|
This point
otherwise return false:
#------------------------------------------#
nothing between...
So if you dont understand just ask please.
I now tried it with Physics.Linecast ... but how do I get this point?
Answer by robertbu · Jan 29, 2013 at 09:15 PM
If you just want to know if something is there you can do:
if (Physics.Raycast (origin,direction))
{
// Do something
}
If you need the position where the raycast hit something:
Ray ray = new Ray(origin, direction);
RaycastHit hit;
if (Physics.Raycast (ray, out hit))
{
// hit.point contains point the ray hit
}
This is C#. Minor variations if using Javascript.
Your answer
Follow this Question
Related Questions
Trying to cast a ray towards an imaginary wall and get a "hit" / "end" point 2 Answers
get the point directly above the raycast collision? 1 Answer
NullReferenceException: Object reference not set to an instance of an object Raycast...? 1 Answer
Trouble with Ray & Raycasting and AddForce() 1 Answer
LineRenderer (Laser Beam) is not following the ray it's going on the wrong direction when reflecting 1 Answer