- Home /
How to make Raycast against LineRenerer
Hi everyone, and sorry for my English.
Here is my problem: i got an object with LineRenderer on it, and i need to select this object by clicking on a line that LineRenderer produces. Is there any way to make this happen? The only idea i got about it is getting mesh from LineRender and making a collider of it, but it seems to be impossible.
Will appreciate any help.
Answer by Kacer · Nov 29, 2011 at 10:55 AM
Well, the linerenderer itself, if i remember correct, does make a mesh. It creates a line from a plane that will always face the camera.
So, if you add a mesh collider to the linerenderer, then you should be able to cast a ray from screenspace into worldspace and get the information you need from the Linerenderer.
It's only a theory, and im not sure it'll work, here's a few links to the documentation: http://unity3d.com/support/documentation/ScriptReference/LineRenderer.html http://unity3d.com/support/documentation/ScriptReference/Camera.ScreenPointToRay.html http://unity3d.com/support/documentation/Components/class-MeshCollider.html
And here's a link to the forums, with a topic that is somewhat relevant to your question: http://forum.unity3d.com/threads/62591-Line-Renderer-Collider
Happy Programming
Your answer
![](https://koobas.hobune.stream/wayback/20220613055932im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Test line renderer collision? 1 Answer
The referenced script on this Behavior ( Game Object 'Camera') is missing. What shall I do? 1 Answer
Linerender/Raycast2D colliding inconsistently with sprites 0 Answers
Predicting ball direction on collision 0 Answers
LineRenderer - Setting Max Distance 1 Answer