What is the best way to fix this dual raycast?

I wrote a dual raycast effect for my main character to detect walls and speed up / slow down as called for, but only the right side gets detected. I’m not sure if the best structure to fit this whole mess into.


Well, you actually don’t need to allocate two RaycastHit objects since you checking them in series. But maybe you should try

Physics.Raycast(transform.position, Vector3.left, out leftHit, 10f)

That might solve your problem, but I doubt it. The problem is probably caused by the fact that you have Physics.Raycast as a condition in an if-else if statement. :wink: Take the else out and your problem should be fixed.