It’s been 20 years since “Good Will Hunting” hit movie theaters and made household names of its screenwriters and stars, Ben Affleck and Matt Damon.

A critical darling, “Good Will Hunting” won two of the nine Oscars for which it was nominated, including one for Affleck and Damon and another for supporting actor Robin Williams — and proved to be lucrative to boot.

According to Box Office Mojo, “Good Will Hunting” earned $225,933,435 worldwide and was ranked as the seventh most lucrative film of 1997.

However, despite the film’s tremendous success, there are still things about its production that even the biggest “Good Will Hunting” fans might not know.

1. The script began as a school project: Damon told Boston Magazine in 2013 that he began writing “Good Will Hunting” for a playwriting class he was taking at Harvard University. After the course ended, he asked his childhood friend Affleck to help him flesh out the story. “We came up with this idea of the brilliant kid and his townie friends, where he was special and the government wanted to get their mitts on him. And it had a very ‘Beverly Hills Cop,’ ‘Midnight Run’ sensibility, where the kids from Boston were giving the NSA the slip all the time,” Affleck told the magazine. “We would improvise and drink like six or 12 beers or whatever and record it with a tape recorder. At the time we imagined the professor and the shrink would be Morgan Freeman and [Robert] De Niro, so we’d do our imitations of Freeman and De Niro. It was kind of hopelessly naive and probably really embarrassing in that respect.” Damon said that the only scene that survived from his initial draft was the one in which his character, a math genius, meets his psychologist, played by Williams.

Ultimately, they dropped the NSA story after Rob Reiner, whose company Castle Rock originally bought the film, told Damon and Affleck that the film needed more focus. “It was a complete overhaul,” Affleck said.

PHOTO: Ben Affleck and Matt Damon in Good Will Hunting, 1997.IMDB
Ben Affleck and Matt Damon in “Good Will Hunting,” 1997.

2. Will Hunting was originally a physics genius: At the suggestion of Harvard professor and Nobel Prize-winning physicist Sheldon Glashow, Damon’s character, Will Hunting, became a mathematics genius instead. Glashow’s brother-in-law, Massachusetts Institute of Technology professor Daniel Kleitman, went on to work with Damon and Affleck to ensure that the dialogue would be authentic. “When they asked me, ‘Can you speak math to us?’ my mouth froze,” he told MIT’s website. “I felt silly mumbling random math so I found a postdoc, Tom Bohman. We went down to the old math lounge in Bldg. 2 and I gave a quick lecture. They took notes, but they didn’t really know what we were talking about.”

“Before I saw the movie, I was worried that the math scenes in the movie would be foolish,” he continued. “But when I saw the movie, I said, ‘They didn’t screw it up!’ and I remember being very pleased.”

3. Mel Gibson could have directed it: Damon told Boston Magazine that their first choice for director was Kevin Smith, who’d directed Affleck in “Chasing Amy.” However, Damon said, Smith passed because he didn’t feel he was right for the project. He did, however, tell his then-friend, now-disgraced producer Harvey Weinstein, to read the script, and Weinstein’s company Miramax ended up purchasing it from Castle Rock in 1995. After Miramax’s acquisition, they met with other potential directors, including Mel Gibson. According to producer Chris Moore, “Mel Gibson developed it for a few months. Matt at one point said directly to Gibson, ‘Look, man. We’re getting too old. If this keeps going by, Ben and I can’t play these parts. Is there any chance you’d just let it go?’ And to Mel’s credit, he said, ‘I totally understand what you’re saying.’ That was a real stand-up thing to do.” Ultimately, they went with director Gus Van Sant, who had worked previously with Affleck’s brother, Casey Affleck, on “To Die For.”

4. Gus Van Sant begged Casey Affleck to be in the film: According to Van Sant, Casey Affleck, who played Hunting’s pal Morgan O’Mally in the film, simply wanted to make a documentary about the making of the film, rather than appearing in it. “It was kind of up to us to beg him,” the director told Variety last year. “He also didn’t have an agent, which was funny. He didn’t see why he needed one. We had to go directly to him to persuade him.”

5. Minnie Driver nearly lost out on the part of Hunting’s girlfriend, Skylar: Although Ben Affleck, Damon and Van Sant thought Driver was perfect for the role of Hunting’s love interest, producer Weinstein didn’t agree. “Harvey Weinstein, who was one of the producers, did not want me at all: I wasn’t sexy enough, I wasn’t cute enough and I wasn’t Gwyneth Paltrow enough,” the actress told The Telegraph newspaper in 2012. “Luckily he backed down.” Weinstein has since been accused of misogynistic behavior and sexual misconduct by dozens of women, and though Driver has said that she “never experienced any abuse” while working with him, she released a statement in support of his alleged victims. Weinstein has denied all allegations of non-consensual sex.

PHOTO: Minnie Driver, Matt Damon and Ben Affleck in Good Will Hunting, 1997.IMDB
Minnie Driver, Matt Damon and Ben Affleck in “Good Will Hunting,” 1997.

6. Robin Williams had a soft spot for his character: One of the most beloved characters in the film was Williams’ Sean Maguire, Hunting’s psychologist, who was reportedly based on Damon’s mother and Ben Affleck’s father. “What drew me to the role just was the idea of a guy trying to give back, who hadn’t been practicing in a while. Here he is, a vet with a history, with a life, an intelligent guy who admits he’s not as brilliant as the kid but who is saying, ‘You’re brilliant but you don’t know s— about certain things.’ That appealed to me deeply,” Williams told Boston Magazine. “What can you give a kid like that? The one thing you can give him is just saying, ‘I can only offer you a certain point of view.’ It’s almost like going through rehab and just trying to say, ‘I know who you are, I know who you think you are. Let’s try to get down to who you are.'” Affleck told the magazine in a separate interview that Williams, who died in 2014, was the “rainmaker” who ensured the film would be made.

7. Ben Affleck and Damon’s characters were almost killed: In the film, Ben Affleck played Hunting’s best friend Chuckie: a lovable goof who knows his genius pal is destined for greater things. However, he almost met an untimely end. Damon told the website Film Scouts that Van Sant wanted Chuckie to be killed on a construction site. Despite their initial protests, “We wrote a draft where Chuckie got crushed like a bug. When Gus read it, he said, ‘It’s a terrible idea,’ so we threw it out,” Damon said. “We also have Will getting killed on our hard drive somewhere. That was an original ending: Carmine came back with his boys and a baseball bat to kill Will Hunting, who deep down actually wanted to be killed. It was his way of getting out. You can kind of sense the movie is going that way. You know: ‘Will drives off into the sunset to find the girl he lost — except for that 18-wheeler that he didn’t see.'”

8. Williams loved to improvise on set: Two years ago, Van Sant spoke about “Good Will Hunting” at the Tribeca Film Festival, and according to the Huffington Post, he gushed over how creative Williams was during filming. In addition to improvising lines (when Damon’s character splits at the end of the movie, Williams went off script and said, “Son of a b—-. You stole my line.”), the late actor regularly goofed off between takes.

“The one thing that was going on, which is a tragedy I wasn’t rolling the cameras, was — especially in Sean’s office — we would do long takes, and it was on film so we didn’t have modern conveniences, like focus was harder and we had to measure everything. The camera would work its way around the room and the characters were working their way around the room and they would have to freeze while we pulled focus,” Van Sant explained. “So, you’d do the lines to make sure you knew where you were going to be in the room … and Robin [Williams] would do his part as Janet Reno and Matt [Damon] would do his part as Daffy Duck. Then the next time around, Robin would choose a different character, Frankenstein, and Matt would be Nixon.

“It was really entertaining and a day after that I was like, ‘Isn’t that great, isn’t that fun that you guys are improving that?’” he continued. “And Matt said, ‘No, it’s exhausting.’ He couldn’t keep up with Robin, Robin’s imagination.”

9. Director Terrence Malick came up with the film’s ending: Sunday Times film critic Tom Shone shared on his website that Damon credited director Malick, who is friends with Ben Affleck’s godfather, with giving them the film’s ending. “We went to Boston to see him. And we had it in the script that my character and Minnie’s left together at the end of the movie. Terry didn’t read the script but we explained the whole story to him, and in the middle of the dinner, he said, ‘I think it would be better if she left and he went after her,'” Damon said. “And Ben and I looked at each other. It was one of those things where you go: Of course that’s better. He said it and he probably doesn’t even remember that he said it. He started talking about Antonioni. ‘In Italian movies, a guy just leaves town at the end and that enough.’ And we said of course that’s enough. That’s where we come from. If you just leave that’s a big enough deal. It doesn’t have to build up to anything more.”