Removing the door collider

I think removing the collider isn’t a great choice to make the door walkable. I noticed when playing that enemy soldiers will take shots through the door-frame and was wondering why, until I watched this lecture!
Because we’re using raycast to determine if a shot can hit, the collider is essential on anything that should block a shot.
Maybe a better solution could be to have multiple layers, one for shooting and another for walkable. Alternatively setting the overshoot distance for the walkable vertical raycast (previous lecture) so it doesn’t reach the top of a door frame… or using the backface collider that you also mentioned in that lecture.

1 Like

Oh right yup I didn’t consider that side effect.

One simple solution is to enable or disable the collider depending on the door state, that way enemies won’t shoot through the door while closed but will work correctly when opened

You can also go with that design of multiple layers but that would complicate the objects quite a bit. Still a valid approach if you intend to have lots of objects with lots of different shoot/walk logic

4 Likes

Another way you can solve this is by adding invisible colliders for the parts of the door frame you don’t want the unit to shoot through. I noticed the units were able to shoot through the frame around the door because we removed the collider, so I went into the prefab and just put in basic blocks matching the shape of the uprights/sides of the frame and put them in the obstacle layer. Then for actual doors, you could just leave their colliders on and move them as normal.

Unless there’s some hidden cost to doing this that I’m unware of because of my lack of experience.

4 Likes

That sounds perfectly valid. You’re just adding a couple of very simple collision objects - I think it’s a better solution than my suggestions :slight_smile:

1 Like

Privacy & Terms