A homeless man who brandished a toy gun at drivers in a busy Swindon street was making a cry for help, a court heard.

Armed officers and the Wiltshire Police helicopter were called out to arrest Matthew Trotman who was pointing the pistol at passing motorists.

At one point the 27-year-old appeared to have his finger on the trigger while he was walking along Mill Lane in Okus.

He was sentenced to 40 hours of community service and put on probation for a year at Swindon Crown Court on Friday. Judge John McNaut was told Trotman, of no fixed address, was not himself when he carried out the offence in July.

He had had trouble with drink and drugs, was depressed and had thought about taking his own life.

A resident of Mill Lane spotted him just after 5pm sitting on the side of the road. When her dog went over to him he drew the plastic gun and pointed it towards the animal and then at her. Kate Brown, prosecuting, said the woman backed away inside to tell her husband who went out to ask Trotman what he was doing.

He replied he was going to shoot "rabbits, humans, anything" and the police were called.

Trotman then walked along Mill Lane, waving the gun at people, and the police were contacted by five other members of the public.

Mrs Brown said: "Armed officers entered and a police helicopter hovered over Mill Lane.

"Then the defendant appeared to become agitated.

"He threw the pistol on the bank and placed it in the middle of the road but at one point he pointed it at the helicopter.

"Firearm officers approached him and told him to put the gun down. He did and was arrested."

When Trotman was interviewed he told officers about his problems and said the only way he could get help was to draw attention to himself in that way.

Trotman's defence counsel, Chris Smyth, told the court his client had been very ill and was taken into hospital for three days after his arrest. "He had been homeless for a week and this was a cry for help of the most dramatic proportions," he said.

Sentencing Trotman, Judge McNaut told him: "It seems you weren't yourself when you did this.

"The probation service think you aren't a risk so I won't pass a prison sentence.

"I hope the combination order of community service and probation will help you to sort your life out, get somewhere proper to live, start working regularly and get things together."