Full Metal Jacket

In 1967, during the Vietnam War, a group of new U.S. Marine Corps recruits arrive at Parris Island, South Carolina, for basic training. After having their heads shaved, they meet Senior Drill Instructor Gunnery Sergeant Hartman, who employs excessively forceful methods to turn the recruits into hardened, combat-ready Marines. Among the recruits are privates "Joker", "Cowboy", and the overweight, bumbling Leonard Lawrence, who earns the nickname "Gomer Pyle" after attracting Hartman's wrath.
Unresponsive to Hartman's discipline, Pyle is eventually paired with Joker. Pyle improves with Joker's help, but his progress halts when Hartman discovers a contraband jelly doughnut in Pyle's foot locker. Believing the recruits have failed to improve Pyle, Hartman adopts a collective punishment policy: every mistake Pyle makes will earn punishment for the rest of the platoon, with Pyle being spared. In retaliation for Pyle's failures, the platoon hazes him with a blanket party, restraining him in his bunk while beating him with bars of soap wrapped in towels. After this incident, Pyle reinvents himself as a model Marine. This impresses Hartman but worries Joker, who recognizes signs of mental breakdown in Pyle, such as him talking to his M14 rifle.
Following their graduation, the recruits receive their Military Occupational Specialty assignments; Joker is assigned to Basic Military Journalism, while most of the others (including Cowboy and Pyle) are assigned to Infantry. During the platoon's final night on Parris Island, Joker discovers Pyle in the bathroom, loading his rifle with live ammunition. Joker attempts to calm Pyle, who executes drill commands and recites the Rifleman's Creed. The noise awakens the platoon, and Hartman confronts Pyle, ordering him to surrender the rifle. Pyle shoots Hartman dead, and then kills himself.
In January 1968, Joker, now a corporal, is a war correspondent in South Vietnam for Stars and Stripes with Private First Class Rafterman, a combat photographer. Rafterman wants to go into combat, as Joker claims he has done. At the Marine base, Joker is mocked for his lack of the thousand-yard stare, indicating his lack of war experience. They are interrupted by the start of the Tet Offensive as the North Vietnamese Army attempts to overrun the base.
The following day, the journalism staff is briefed about enemy attacks throughout South Vietnam. Joker is sent to Phu Bai, accompanied by Rafterman. They meet the Lusthog Squad, where Cowboy is now a sergeant. Joker accompanies the squad during the Battle of Huáº¿, where platoon commander "Touchdown" is killed by the enemy. After the Marines declare the area secure, a team of American news journalists and reporters enters Huáº¿ and interviews various Marines about their experiences in Vietnam and their opinions about the war.
During patrol, Crazy Earl, the squad leader, is killed by a booby trap, leaving Cowboy in command. The squad becomes lost and Cowboy orders Eightball to scout the area. A Viet Cong sniper wounds Eightball and the squad medic, Doc Jay, is also wounded while attempting to save him, against orders. Cowboy learns that tank support is unavailable and orders the team to prepare for withdrawal. The squad's machine gunner, Animal Mother, disobeys Cowboy and attempts to save his teammates. He discovers there is only one sniper, but Doc Jay and Eightball are killed when Doc Jay attempts to indicate the sniper's location. While maneuvering toward the sniper, Cowboy is shot and killed.
Animal Mother assumes command of the squad and leads an attack on the sniper. Joker discovers the sniper, a teenage girl, and attempts to shoot her, but his rifle jams and alerts her to his presence. Rafterman shoots the sniper, mortally wounding her. As the squad converges, the sniper begs for death, prompting an argument about whether or not to kill her. Animal Mother decides to allow a mercy killing only if Joker performs it. After some hesitation, Joker shoots her. The Marines congratulate him on his kill as Joker stares into the distance, displaying the thousand-yard stare. The Marines march toward their camp, singing the "Mickey Mouse March". Joker states that despite being "in a world of shit", he is glad to be alive and no longer afraid.

Question: What inanimate object did Pyle begin talking to?
Answer: rifle