Lieutenant Commander Ian Molyneux was killed by Able Seaman Ryan Donovan on board HMS Astute docked at Southampton on April 8, 2011.
The 23-year-old was jailed for life with a minimum tariff of 25 years after pleading guilty at Winchester Crown Court to the murder of Lt Cdr Molyneux and attempted murder of LLt Cdr Christopher Hodge, 45.
The court heard that his real targets, whom he also admitted to attempting to murder, were Petty Officer Christopher Brown, 36, and Chief Petty Officer David McCoy, 37.
CPO McCoy told the inquest at Southampton he believed he had a good working relationship with Donovan but after a disciplinary action over a cleaning task, this changed.
Richard Wilkinson, counsel for Lt Cdr Molyneux's family, said four other sailors claimed Donovan did not get on with CPO McCoy and PO Brown and a previous captain said they had "rode him hard".
Donovan was facing disciplinary procedures for disobeying orders and a transfer for an operational tour on RFA Cardigan Bay was cancelled, the inquest heard. CPO McCoy said: "In his eyes, when he saw me and Brown, we were the bad guys, the ones who stopped him going on his operational tour."
CPO McCoy said he had seen Donovan approaching him, firing the SA80 rifle, and had jumped straight down a ladder hole connecting decks.
The hearing continues.