R. Lee Ermey in 2006. (Randy Davey/The Jacksonville Daily News/AP)

R. Lee Ermey, a character actor who drew on his experience as a Marine Corps drill instructor during the Vietnam War to portray the violent, howling sergeant in filmmaker Stanley Kubrick’s “Full Metal Jacket,” died April 15 at a hospital in Santa Monica, Calif. He was 74.

The cause was complications of pneumonia, said his manager, Bill Rogin.

Mr. Ermey, an 11-year veteran of the Marines, had more than 100 film and television credits, including as a voice actor in children’s television series and in the “Toy Story” movies, in which he played the plastic soldier Sarge. But he was best known for his gruff and profane roles in Vietnam films, beginning with a drill instructor part in “The Boys in Company C” (1978).

He had initially been hired as a military adviser for the film but was reportedly cast after director Sidney J. Furie saw him teaching another actor how to play the role of the movie’s foul-mouthed sergeant.

“Jesus,” Mr. Ermey says in the film, delivering an expletive-laden speech to his latest batch of “maggots.” “How in the hell do they expect me to train . . . Marines when they won’t even send me human . . . beings to start with?”

Mr. Ermey, who went by “Gunny,” played an even more nightmarish instructor in “Full Metal Jacket” (1987), about a platoon of Marine recruits deployed to Vietnam. As with his earlier role, the part was inspired by his service as a drill sergeant at the Marine training center on Parris Island, S.C., where he said he and other instructors sometimes “raised a hand” to privates who failed to follow orders.

“My main objective was just basically to play the drill instructor the way the drill instructor was — now let the chips fall where they may,” he said in the 2001 documentary “Sarge!”

As Gunnery Sgt. Hartman, Mr. Ermey took the art of the insult to sadistic extremes, threatening to “gouge out” the eyeballs of slow-moving recruits and then sexually abuse them. Mr. Ermey created about half his dialogue for the film, Kubrick said.

“In the course of hiring the Marine recruits, we interviewed hundreds of guys,” the director told Rolling Stone in 1987. “We lined them all up and did an improvisation of the first meeting with the drill instructor. They didn’t know what he was going to say, and we could see how they reacted. Lee came up with, I don’t know, 150 pages of insults.”

Among Hartman’s preferred targets was a misfit named Lawrence (Vincent D’Onofrio), a name that Hartman said belonged only to “[gays] and sailors.” The sergeant dubbed him Gomer Pyle, after the simple-minded character in “The Andy Griffith Show.”

“Ermey plays a character in the great tradition of movie drill instructors, but with great brio and amazingly creative obscenity,” movie critic Roger Ebert wrote. “All situations in the Marines and in war seem to suggest sexual parallels for him, and one of the film’s best moments has the recruits going to bed with their rifles and reciting a poem of love to them.”

Mr. Ermey went on to appear in weapons-focused television series such as “Mail Call,” which reportedly became the History Channel’s highest-rated program when it premiered in 2002, and served as a board member for the National Rifle Association and a spokesman for Glock. He also served as a longtime spokesman for the Marines’ Toys for Tots program.

“I figure I’ve fought the Vietnam War five times,” he told the Associated Press in 1987, reflecting on his career. “The next time a producer calls up and asks me to take part, I’m gonna see if we can’t win the . . . thing.”

Ronald Lee Ermey was born into a farming family in Emporia, Kan., on March 24, 1944. A self-described “hell-raiser,” he moved to Washington state with his family at 11 and said he was twice arrested for “joyriding” and “beer drinking” when a judge gave him an ultimatum.

“He said I could either go into the military — any branch I wanted to go to — or he was going to send me where the sun never shines,” Mr. Ermey told an interviewer with the Civilian Marksmanship Program. “And I love sunshine, I don’t know about you.”

Mr. Ermey was rejected by the Navy before entering the Marines in 1961. His military career effectively ended eight years later when he was wounded by a rocket near the Vietnamese city of Danang. He bought “a run-down bar and whorehouse in Okinawa,” he said, and still had shrapnel in his back and shoulder when he began studying drama at the University of Manila.

When director Francis Ford Coppola arrived in the Philippines to film “Apocalypse Now” (1979), Mr. Ermey met him at the airport. He went on to appear in the movie as an uncredited helicopter pilot who participates in a strike against a Vietnamese village while Wagner’s “Ride of the Valkyries” blares through a set of speakers.

Survivors include his wife of 37 years, the former Marianila Ypon; six children; two brothers; and many grandchildren and great-grandchildren.

In the 1990s, Mr. Ermey became frustrated with being typecast and refused to take new military roles in movies. He played the distraught father of a murder victim in “Dead Man Walking” (1995) and a gay football coach in “Saving Silverman” (2001), but largely stuck to playing authority figures such as a small-town mayor in “Mississippi Burning” (1988), a police captain in “Se7en” (1995) and a sheriff in the 2003 remake of “The Texas Chainsaw Massacre.”

Despite his prolific output, he said he was “blackballed” for his conservative-leaning views in liberal Hollywood, and expressed disappointment that he was unable to appear in more films like “Prefontaine” (1997), in which he played Nike co-founder Bill Bowerman.

“I don’t know what it is with these idiots down there in Hollywood,” he told Entertainment Weekly upon its release, suggesting that there were few financial backers for serious, small-scale dramas. “They just have no taste.”