- Home /
Question by
Rubinreiser · May 17, 2021 at 04:57 PM ·
raycastcolliderhit
Raycast ignore Boxcollider
Hello ,i have a laser Turret in my Game and the laser should just stop when it hits a collider (wall). The problem is that the Raycast that is created just ignore the fact that there is a boxcollider. The boxcollider isn't set "is trigger" and the wall isn't on the "Ignore Raycasts" Layer. This is my simple script so far. I hope somebody can help me.
public class LaserTurretScript : MonoBehaviour { private LineRenderer LineR;
void Start()
{
LineR = GetComponent<LineRenderer>();
}
void LateUpdate()
{
RaycastHit hit;
LineR.SetPosition(0, transform.position);
if (Physics.Raycast(new Vector3(1, 0, 0), transform.up, out hit))
{
if (hit.collider)
{
//If a collider gets hit
LineR.SetPosition(1, hit.point);
}
}
else LineR.SetPosition(1, transform.up * 4000);
}
}
Comment
Your answer
Follow this Question
Related Questions
Click&Drag Misterious Disappearing! 1 Answer
How to limit a ray to go downwards to infinity, how can I make it down only 1 float. 0 Answers
How to hit two object with one raycast? 2 Answers
Raycasting and receiving hit.colliders with two cameras 0 Answers
I don't know why i can't detect by ray sth. tagged, 1 Answer