I know in California, from experience, if they are on "your threshold" and threatening you, you have the right to defend yourself/shoot them. So, even if you live in an apartment, if they come up a set of stairs that only lead to your apartment, that first step/rung is your threshold. If they are on the walkway of your house, heading to your door with demonstrated ill intent, yep, you can defend yourself.
It's happened to me twice, when living in a not so great part of town.
Also had my porch light shot out by the police, as they prepared a breach on a meth head who car jacked a vehicle the next town over, got pursued, bailed out of the vehicle next to the apartment complex, came up my stairs (I wasn't home at the time) and hopped from my stair railing onto my neighbor's balcony. She (single mom) heard a noise, saw the helicopter search light, and ignorantly opened her balcony sliding glass door to see what was going on (unarmed). Perp took her and her two sons hostage with a knife. Cops initially were planning to breach through my bedroom wall, but after I arrived and informed them of the ammo, gun powder and weapons in my place, they decided to go through another neighbor's adjoining wall (see, owning guns does help in other ways
). So, they punched a hole in the wall of the neighbor's bathroom (common wall with my neighbors bathroom), and during the ruckus, one of the boys got out. Police pushed a tear gas grenade through the hole in the wall, and when it went off the perp panicked, and tried to smother it. The Mom grabbed the other kid and hightailed it out the front door. SWAT went in frontal and took said perp into custody. No extra holes in him, but he did have some extra dents and "ow-eees".
...Meanwhile I spent the night sleeping in my truck in the nearby Wal-mart parking lot, waiting until the 4am breach was done. What a shitty way to spend Thanksgiving Day evening...
That's still a shitty part of town, but my career bloomed, which meant I no longer had to live in that shit hole. Tweekers and gang bangers...smdh. I guess my "white privilege" didn't protect me from that crap in that shit hole...