I have a FPS gun setup, but there is no collision for it with terrain objects.
How do i fix this?
Add a collider to it. Box or cylinder should work nicely depending on your guns shape.
No that wont work I attached a pic of what its doing.
The manual says how to fix it but its not clear enough and i dont understand
See how it goes right through the terrain?
If it goes thru the terrain, it’ll probably go thru walls as well.
I know alot of games use a raycast to determine if the model will poke thru something, if so, it’ll play an animation of the gun being pulled back, or pointed up or something like that.
Basically if your gun sticks out 1 unit, and you are less then one unit away, it will poke thru, so you’d need to play the animation to adjust the gun.
Alternatively, there’s the option of rendering the gun above everything else via layers. I think this is what the FPS tutorial tells you to do.
Depth buffering using two camera’s.
Could you tell me exatly how to do the depth-buffer? Like I already said, I tried what the manual said but it gave so little info I dont understand it
-Create a new layer for your weapons. Set all your weapon’s layers to this new layer.
-Now create a second camera, set it to render only the new Layer, your weapon’s layer. Set it’s ClearFlags to Depth Only.
-Set your main camera to not render the weapon’s layer.
-Give it a higher depth value then the main camera.
If you do all these correctly, it will solve your problem. There is no need for any scripts, these are mostly done in your camera object settings in the inspector window.
Do this, it works for me.
It really works? perhaps I will try this. I tried the raise gun thing, but getting everything to work right is hard. And using box coulliders on simple map parts works, but not on meshes. So im gonna give this a try!
HOLY F**K! IT WORKS! That is truly amazing! Thanks a lot!
:roll:
You are welcome, it’s the technique used in almost all the FPS games out in the market today.
I suppose so. Back in the pre-2000’s, the gun was simply an animated part of the GUI, not a real object.
How do i create a layer ?
Go to the top of the inspector, click the drop-down that says “Layer”, and click “Add New Layer”.