The stark, cavernous interior of a Hercules C130 aircraft is an unlikely place for inspiration to strike, but for Lieutenant Colonel Christopher MacGregor it was the perfect moment to start writing a book for his two children, explaining why he had been away.

MacGregor, who leads the regiment of the King's Royal Hussars, was flying home in 2007 following six months in Basra, Iraq, when he realised the "single most significant factor" affecting his men's performance had been their family relationships.

Although there are groups to support wives and families of service personnel, nothing is available specifically for children to help explain where their fathers have gone and why. So MacGregor, strapped into his seat in the Hercules, started writing the opening lines to a book for Ben, then three and a half, and Ellie, one and a half, called My Daddy's Going Away.

But the Ministry of Defence was not interested, and neither were dozens of publishers he contacted. Eventually, MacGregor put up £5,000 of his own money to self-publish 2,000 copies. But now he has sold 8,000 copies of the book, for which Prince Charles – himself the father of two servicemen – provided the foreword, and it is now being used by mining companies in Australia and families of oil-rig workers. "I've broken even financially now, and my wife isn't angry with me any more," he says with a laugh.

MacGregor, who is 38 and lives near Reading with his wife, Vicky, and their children, now aged seven and five, says: "At the end of my Iraq tour, I realised we had done a lot of work in ensuring the soldiers' relationships were sound before they left, and that they had all the loose ends of everyday life tied up. But what I found was that those soldiers who had not tidied their affairs – whether it was the car insurance or other things – found the tour harder."

A significant factor for many men was wondering whether they were leaving behind confused, upset children. "If those relationships were secure, they performed better for me. It was in my interest to ensure their personal affairs were sorted out."

And so came the inspiration for writing a book to help young children and, by default, their parents. "It works two ways. In the short term, you're saving a marriage and in the long term, you're ensuring the army has that asset in the future," he says.

He had been abroad on operational tours during his 17 years in the army, but never as a family man, and drew on his own experiences to help him write the book because leaving for Iraq presented him with a new set of challenges.

MacGregor, who has now been deployed to Afghanistan, says: "Iraq was the first time I had been to a dangerous combat area. It was very difficult. As the tour approaches, you focus on the job you're going to do and the place you're going to do it. That puts a strain on your relationship and you feel guilty for trying to split yourself in half. You're thinking about the soldiers you're going to lead, but you're also still trying to be Daddy."

That meant explaining to his children where he was going and why. "They knew I wasn't going to be on my own. When they start asking why, that became an interesting question to answer. It has to be simplified right down. You might say that you're helping children go to school, or making sure people have clean drinking water."

"Children are naturally inquisitive and want to know where you live, what your room is like and what you had for dinner." He would send back sand from the desert and stones so they could connect with him being there. "It's about trying to meet the inquisitiveness with answers they can understand. You don't want it to be scary. Afghanistan and Iraq are the bogeymen who take their daddy away. It is much better to talk about it. It's not just a desert where there is blood and death, there are remarkable stories of beauty and love."

This is his second tour since becoming a dad: "It never gets easier. Ellie is quite put out at the moment and she is really badly affected. Ben is more affected than last time, too. He takes my book to school and reads it at quiet time. He talks to me on the phone, but won't talk to his mum about me being away."

MacGregor is trying to arrange his leave to coincide with the half-term holidays. Vicky is studying full-time to be a primary school teacher and won't be around, so it will be down to him to do the childcare, entertaining, feeding, washing and dressing.

"What will I do when I get home? Daddy things. I'll be climbed on and listening with feigned interest as Ellie tells me about potty training her doll."

• My Daddy's Going Away by Christopher MacGregor is available from mydaddysgoingaway.com