Raycast goes (sometimes) through collider
Hi there. I've a annoying problem, where the detection RayCast goes sometimes through walls.
Most times it works how it should, but in the last time i recognize more often this problem (i didnt change the script since a long time, and most times its working correctly).
Following the script i use (JavaScript) and two Screenshots where i caught the renegade Defensetower ("Player" is outside somewhere behind the tunnelwall on a hill, so there are at least two collider between them)... what to do? Its not a funny game when you're getting hit through walls.
function FixedUpdate(){
for (Entity in IntruderList){
if (Physics.Raycast(transform.position, (Entity.transform.position - transform.position), Hit)){
Debug.DrawRay(transform.position, (Entity.transform.position - transform.position) * 30, Color.yellow);
if (Hit.collider.tag == "Player" || Hit.collider.tag == "Entity"){
Target = Entity;
IsSeeingTarget = true;
IsSearching = false;
Distance = Hit.distance;
} else {
IsSeeingTarget = false;
IsSearching = true;
LetsShoot = false;
}
}
}
if (IsSeeingTarget == true){
WarningCycle();
}
}
Did you find a solution for this? I have the same problem except the rays are firing through a building ins$$anonymous$$d of a tunnel and I'm using c#.
Never $$anonymous$$d, I fixed my issue. One of the nearby npcs had a "Player" tag when it shouldn't have. Hope you found/find your solution. One thing you might try is moving your raycasting to FixedUpdate ins$$anonymous$$d of regular Update. While searching for solutions I noticed that was suggested.
Your answer
Follow this Question
Related Questions
Animating a click to move character 1 Answer
Does Unity support raycasting to meshcolliders from FBX files ? 0 Answers
Problem making object keep on RaycastHit point relative to another object 0 Answers
How to make raycast ignore objects on layer based on distance to caster? 1 Answer
NullReferenceException on Raycast 0 Answers