- Home /
how to get info on what raycast hitted
Basically, I wanted to determine whether there is any obstacle between Player and Target. And then return the target info. I tried to use Raycast, but feel free to offer alternative if you can provide one.
I managed to get the Raycast line stopped at where the collider is. But I don't know how to get the variables from the object which the collider is attached to.
Also, is there anyway to widen the ray? In case the player might not be able to pass through gap between objects.
Code so far:
public Transform Player;
public Transform TargetLocationFinal;
void DrawRayCast()
{
RaycastHit hit = new RaycastHit();
Vector3 direction = TargetLocationFinal.transform.position - Player.transform.position;
if (Physics.Raycast(Player.transform.position, direction , out hit))
{
Debug.DrawLine (Player.transform.position, hit.point);
}
}
Answer by Berenger · Jun 05, 2012 at 10:50 PM
All the information is in your RaycastHit. you have access to the collider, and from there everything with GetComponent.
You can't widen the ray, but you can cast several by spacing them of transform.right, left, up etc.
Your answer
Follow this Question
Related Questions
Click&Drag Misterious Disappearing! 1 Answer
I don't know why i can't detect by ray sth. tagged, 1 Answer
Need Help with RayCast. No Vector? 1 Answer
how to select an object with raycasting 1 Answer
Raycast retuning info of hit object 1 Answer