M. Night Shyamalan started filming "After Earth" in February 2012. Before that, Gary Whitta wrote the first script, then M. Night Shyamalan rewrote it, then Stephen Gaghan improved M. Night Shyamalan's script at the end of 2011. M. Night Shyamalan filmed most of the movie in Costa Rica, California, and Pennsylvania.