Raycast from camera only working from certain angles
So with a first person character I'm using raycasts to check for interactions of the player. I first made doors, which work fine. Then I made a key on the ground which didn't seem to work properly. Then a cupboard with two doors and two drawers, each with a collider to open separately. All except for the door are working really weirdly. Even thpugh the raycast is hitting it, it says nothing is being hit :( thanks!
The first two images show an angle where the camera doesn't detect the object to interact for some reason (bigger crosshair means you can interact). The next two show an angle where it detects the object. ????????
I'm having the same problem. Did you find the solution?
The funny thing is that with me the problem only happens when I shoot objects of certain layers. Some layers are working well, some are having this problem.
Answer by FairGamesProductions · Jun 05, 2019 at 01:39 PM
It looks like you don't have any LayerMask set for the raycast. This means that at certain angles the raycast is colliding with the collider of the FPS character and blocking it.
You should set a public LayerMask variable and set your desired interaction layers there, but don't forget to add the relevant objects to those layers.
Your answer
Follow this Question
Related Questions
RayCast From Centre of Camera 1 Answer
Mouse click doesnt seem to be hitting the right collider 1 Answer
C# Door Script Problem 0 Answers
3rd person shooter- fire at where crosshairs are pointing to 0 Answers
Raycast with image over collider 0 Answers