- Home /
Player's gun go through all object in the game
Player have a gun, which is Player's child object. When he moves too close to any object, the gun go through it. How can I solve it?
Increase the collider of your Character, until its not happening anymore.
To achieve the desired effect I have too much to increase the collider. In such case I will got problems with the movement of the player
If that it's not an option the only way would to detect if there is a wall and change the animation to another where the gun is held different.
Answer by RealMTG · Jun 22, 2015 at 02:56 PM
Brackeys made a very good video about this some time ago. You can check it out here.
But basically you need two cameras. Parent the "weapon camera" to the main camera of your player. Remove all the components except the camera component from the weapon camera. Now on the camera component of the weapon camera, change the Depth to 1 and the Clear Flags to Depth Only. Now create a layer or use an old one and assign that layer to your gun. On the main camera of the player, in the culling mask, uncheck the layer the gun is on. Now on the weapon camera, on culling mask, uncheck everything except the layer the gun is on.
But please be aware of this! The gun will still go through the level but the player won't be able to see it! And if you have your shoot position in the gun, the player may be able to shoot through the wall if it is thin enough!
I hope this helped you!
Answer by Andy.... · Jun 22, 2015 at 03:43 PM
One solution (maybe not the best one, but still common) is to create a second camera, which render only the weapon, and change it to render before the game's main camera. I've seen this solution from old to new games.
Your answer
Follow this Question
Related Questions
Fast moving object passing through other objects. 6 Answers
OnCollisionExit not being called 0 Answers
How do I use rigidbody's collision detection modes? 2 Answers
add collision to animated object 1 Answer
Terrain collision problem 1 Answer