# Bullet collides with wall behind player

Hi everyone,

I’m messing around with a 2D/2.5D isometric shooter like Nuclear Throne for practice and my player is having problems shooting while “hugging” a wall. My bullets collide with walls and are destroyed, but when my player shoots downward or to the side while he’s touching the wall, the bullet collider touches the wall collider and acts like a collision and destroys itself.

How do I address this? Would the wall collisions have to read velocity of the bullet? Layering doesn’t work because I still want the bullet to collide with other walls, so I’m not sure how to code restrictions on the wall and bullet collision.

Thanks!

I’d recommend 2 things to check, firs the Physics or 2dPhysics layers, make sure everything is testing collision properly.
And second if you are instantiating a buttlet, check the start position of it, if you are using the player relative position and it starts from the middle of it, it might be starting inside a wall. Maybe move that starting point to an empty object with relative position of the bullet hole of the gun.

Thanks for the reply! The thing is on other occasions I do want the bullet to collide with the wall like it is doing, but not when the wall is considered behind the player. I know it’s all in 2D so 2D collisions will occur regardless of the depth I try to create, so that’s why I’m trying to find a way to create that depth with the bullets as I’ve already done so visually.

Here’s my projectile collision code for hitting when it collides with a wall. This works as intended, but when my player is hugging a wall and shoots downwards, the bullet collides with the wall that’s supposed to be behind him, and destroys the bullet.

``````    public void OnCollisionEnter2D(Collision2D other) //Added 2D to calcualtion
{

if (other.collider.tag == "Wall")
{
if(!collided)
{
//print("FLAT WALL");
collided = true;
WallClass wallCall = other.collider.GetComponent<WallClass>();

ContactPoint2D collisionPoint = other.contacts[0];
//sprint(other.contacts[0].otherCollider.name);
HitFX(collisionPoint.point, wallCall);
if (wallCall.WallFacingID == 1)
{
ChooseRandomBulletHole(collisionPoint.point, wallCall);
}

ProjectileDestroyAction();

}
}
}
``````

If you can see Nuclear Throne @0:33, the player hugs the wall and shoots but the bullet does not collide with the wall even though in my game it does. Here is a visual example of my game situation:

So its reading the collision, which it is supposed to, but the bullet logically should never collide with a wall behind it when it is shot at this angle. I still want the bullet to collide if the player were to be shooting upward at this wall. Do I have to check the velocity of the bullet to determine what is allowed to be collided with the wall? Thanks in advance.

oh ok yeah i’d just temporarily disable collision for the start of the bullet if player is touching.the wall.