- Home /
Gun and player model clipping through walls. How do I fix WITHOUT using multiple cameras?
Hey guys, I've been struggling with this issue for quite a long time now. I am creating a simple FPS with a full body player model setup. The problem is that my guns and player model clip through geometry sometimes (especially in corners and face-to-wall).
I tried creating a second camera that clears depth only and only draws my player model layer, but then my player model and gun don't cast shadows.
Then I tried creating a "pull gun back" animation that plays whenever a raycast detects colliders in front of the player, but that isn't precise enough either, as the time the animation needs to transition into the pulled back position is enough to see the gun clipping through geometry for like 0.3 seconds at corners (and especially at very tangent angles from walls whilst walking/running).
Can somebody help me fix this? Thanks in advance :)
For realism, don't allow your player to get so close to the wall.
$$anonymous$$ight sound like a crap suggestion; if you are using physics this won't be a problem, I think.
$$anonymous$$ake your colliders and bounds slightly larger.
If you are using $$anonymous$$ecanim, you could consider implementing the Leaning as a BlendShape. On detecting a collision with the wall the lean can be set to go no further than its current lean.
If you use Blender this is called Shape$$anonymous$$eys.
Yup, thought of that too :D
But the problem is not much within the leaning per se, but rather the fact that with such "big-ish" colliders and bounds you would never even get so close to a wall to actually need the leaning functionality at all :/
That's a good consideration.
I think the only game I user used a Lean was in $$anonymous$$GS and that was probably just to play with PS2 pressure sensitive buttons :D I end up getting frustrated that games have Lean on PC as I like my E button to be 'Use' :P
Games have handled this differently since the dawn of time (If the dawn of time is when FPS games came out). Some do the back-against-the-wall routine. Camera/Layer trickery in others. If there is no $$anonymous$$ultiplayer involved, so noone observing your Player model in 3rd person you can get away with a pull-back in the form of the weapon disappearing back in to the camera, -Z stylee. Imagine your face up against a wall... the camera moves forward but the gun stays still so you can no longer see it. I guess retract rather than pull back; disappearing under the camera, per se.
Yep, I decided to stick with the weapon retract/pull back method :) thanks
PS: high-five for $$anonymous$$GS-love :')