- Home /
Line Renderer Collision Detection.
Hi,how can i make line renderer detects collisions on its way (Player) and when collision is detected then print("player detected")
Answer by greenshadow · May 12, 2013 at 06:56 AM
I think you're looking for something like this (C#)...
RaycastHit hit;
if (Physics.Raycast (lineStartPosition, lineEndPosition - lineStartPosition, out hit)) {
switch(hit.transform.gameObject.tag)
{
case "Player":
//Output message
print("player detected");
break;
}
}
Hey greenshadow,nice script,looks like it should work,but the script is wrong written and full of errors,i mean it dont works,can you please write script correctly?
$$anonymous$$ark, the script does work, I use it in a game I am making right now. The only thing is that "lineStartPosition" and "lineEndPosition" are Vector3 variables, but not variables that are defined in Unity namespace. You must replace them with your own Vector3s that you used to set your Line Renderer positions with.
$$anonymous$$aybe you can paste in a snippet of your current code for the Line Renderer, and I can show you from there.
Answer by DaveA · Oct 23, 2012 at 06:03 PM
You may need to Raycast each line segment yourself. I hope there is a better answer
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Raycast Destroys player. 1 Answer
Player destroys when he touches particle effect. 1 Answer
GUI cale and position according to the actual screen resolution. 1 Answer
C# Reload Script 1 Answer