- Home /
First Person Weapons clip with terrain geometry
Hello
Currently in a first person game I am developing in C# I find that if I aim towards an object or part of some terrain that the weapon clips through it.
I am not to wise with scripting so I would be very thankful of a possible fix.
At the moment for fixes I have thought about making the weapon on another layer to stop clipping, or to play an animation of the weapon drawing more towards the player when an object is within close proximity.
Sadly I do not know how to go about either solution so if I could be shown how to approach both methods that I have suggested or any other methods to avoid clipping then I would appreciate it.
Thanks.
PS: Just to reiterate I am developing the game in C#.
Already asked/answered: http://answers.unity3d.com/questions/10620/always-render-a-object-on-top-of-another
Answer by maxwelldoggums · Aug 28, 2012 at 10:25 AM
I've just figured this out recently! :D What you need to do, is draw the weapon separately, and overlay it onto the main game camera.
Put your weapon model in a new layer using the inspector, then create a new camera. Specify your main camera to not render the weapon layer. You can do this using the "culling mask" field of the camera in the inspector. Next, set the new camera to ONLY render the weapon model. Then, set the new camera's "Depth" to 1, putting the weapon camera drawing viewport "in front" of the main camera. Finally, set the weapon camera's "Clear Flag" to don't clear, making the background transparent for this viewport. This should draw the weapon on top of the rest of the scene, and with no scripting whatsoever, you can draw your weapons on top of the scene.
Answer by WoodStick · Oct 23, 2016 at 04:52 PM
This unfortunately didn't help me with the issue. It worked after following your steps and setting the cameras projection to "orthographic" (with a size of approx .5).
I suggest making the gun and arms very small, small enough that they will fit inside the character's collider. If you set the position correctly, there will be no difference and this solution has no issues with lighting etc.
Of course, it requires you to use seperate GameObjects for viewport and world models. However, thisi s actually what pretty much all modern FPS games do, where the viewport model is typically much more detailed than the world model, and sometimes also stretched along the z axis for a nicer appearance from the player's view.
Your answer
Follow this Question
Related Questions
FPS Weapon and animation 1 Answer
Select Object ( Weapon ) Quick! Help! xD 1 Answer
FPS animations for different purposes? 1 Answer
Switch Weapon Script Not taking effect HELP!! 2 Answers
Multiple Weapon Animation Help 0 Answers