Hi
The Guns in my game do not have a collider on them.
They have CapsuleCollider with isTrigger = true. This is on purpose because of the desired character movement I want to achieve on the character (only the player’s capsule collider is used to prevent going through walls)
So, as a result the gun can enter the walls and shoot through.
To prevent shooting when the gun’s inside a wall, I did this :
The gun has a script : GunCollissionHandler
Since the gun has a CapsuleCollider Trigger, I do this:
Whenever gun enters a wall,
OnTriggerEnter(Collider other){
if(other.layer = "Wall"){
isInsideWall = true;
}
}
OnTriggerExit(Collider other){
if(other.layer = "Wall"){
isInsideWall = false;
}
}
Then when shoot button is pressed, obviously I shoot when isInsideWall is false.
But this has a problem (at the corners of the room apparently). When character rotates, the gun moves from inside one wall to another. It’s isInsideWall becomes wall and It can shoot, even though it is inside another wall.
I even tried counting the colliders, like this :
OnTriggerEnter(Collider other){
if(other.layer = "Wall"){
numWallsInside++;
}
}
OnTriggerExit(Collider other){
if(other.layer = "Wall"){
numWallsInside--;
}
}
Then, when shooting, check if (numWallsInside < 1). This also fails in some cases of death and respawn.
I hope you understand the problem.
Thanks.