Two Pennsylvania men accused of shooting a pellet gun in Ocean City apparently picked the wrong target early Wednesday, when one of their shots hit an unmarked police car, police said.

Just after midnight, two Ocean City police officers were patrolling in the unmarked car on Ocean Avenue, police said in a news release. As they were driving, the officers saw an object enter the car and ricochet around. They realized immediately that they had been shot at by someone using a pellet gun, the release states.

The officers spotted several men on the third-floor porch of a house in the 1100 block of Ocean Avenue. They went to the house and spoke with the tenants. Police said Benjamin Hemphill, 18, of Richland, Pa., and John Baker, 20, of Myerstown, Pa., had been shooting an Airsoft gun from the third-floor porch at passing vehicles. Officers found two Airsoft guns in the third-floor unit.

Airsoft guns are used in a sport similar to paintball, where players shoot at each other with realistic-looking guns that shoot plastic pellets.

The men were arrested and charged with possessing a weapon for an unlawful purpose. They were released on summonses.