About 7.30pm they were involved in another incident on the Symonds St onramp in the city when their car nearly collided with another vehicle.
As the two vehicles drove south down the motorway, Williams produced an air pistol and pointed it at the occupants of the other car, including a 7-year-old boy.
"It was a stupid act and also an arrogant act which caused the people in the other car to be frightened for their lives,'' Justice Lang said.
When the group arrived at Williams' Manurewa home, Mr Townsley and another boy went into the garden to urinate.
Williams produced a high-powered air rifle and told another member of the group "dude, watch this''.
He looked through the scope, aimed in the general direction of Mr Townsley and pulled the trigger.
The Crown accepted that Williams had been intending to shoot a can and not his friend of many years.
However, Mr Townsley clutched his left side and said "I got hit'' before dropping to the ground.
"I'm sorry, I'm sorry, I didn't mean to,'' Williams told him.
Mr Townsley underwent surgery but could not be saved.
A post-mortem examination revealed the pellet had lodged in his heart.
Justice Lang was given victim impact statements from members of Mr Townsley's family, some of whom were in court today.
"The effect of the loss has been devastating for them,'' he said.
"They will take many years to come to terms with what you have done.''
The community needed to know that it was not acceptable to drink alcohol, smoke cannabis and mess around with guns, he said.
The court was told that Williams had issues relating to alcohol and anger management.
However, Justice Lang was satisfied that the anger issues did not contribute to the events of that day, "rather these incidents involved the stupid and foolhardy use of deadly firearms''.