Stop Gun clipping into objects in Google VR (Cardboard) FPS game
Trying to stop clipping of my FPS gun into walls, for a VR game I'm making.
Traditional fixes seem to use multiple cameras, but I can't use this method for a VR camera setup.
I tried using the super useful script at: https://forum.unity3d.com/threads/drawing-order-of-meshes-and-sprites.212006/#post-2899026 as well as other similar scripted ways, to set the SortingLayer layer and sortingOrder on the gun mesh but these don't seem to have any effect. Is this something special about the Gvr camera?
Are there any other workaround?
Many thanks
Answer by sutdisi · Feb 09, 2017 at 12:08 AM
Hi @baroquedub,
I had the same issue. I was able to get multiple camera solution working against clipping. This was my setup:
GvrMain ->Head ->Main Camera
I added a second camera under the head, then applied the solution using culling mask you mentioned. Also don't forget to increase the depth of this second camera so it'll draw on top of the main camera.
You're a star! That did it :)
Just to be clear to anyone else interested, I used this method for fixing the clipping: http://answers.unity3d.com/questions/41298/fps-gun-clippes-through-walls.html and placed the gun camera as a child of the main camera: Gvr$$anonymous$$ain ->Head ->$$anonymous$$ain Camera-> gunCamera (Works on Cardboard and GearVR)
[edit] weirdly this worked fine in the editor but was broken in my builds. As was originally suggested by @sutdisi the gunCamera does need to be a child of the Head. Unfortunately I've found that on Gear VR this makes the camera lag a bit (I guess because of the additional overdraw) so I've decided not to use it. Shame!
Sorry, this didn't work for you. For anyone curious I used this on iOS and it worked fine.
Don't get me wrong. It works. and I was very grateful for your answer. It's just that the performance hit on my game isn't making it worth my while implementing it. (I'm pretty sure it's related to the additional overdraw)
Your answer
Follow this Question
Related Questions
X ray shader 1 Answer
Why do objects clip through eachother in VR (XR)? (Oculus quest 2) 0 Answers
FPS Weapon Clipping 1 Answer