This answer may be vague, in the linked video, it shows that a data pack is used. The data pack will require a right click detection system. When right-clicked, an armour stand will be summoned to the player shooting the hitscan gun. The armour stand will then travel in the direction the player is looking via the teleport command. When it hits an entity, it will do instant damage, and then the armour stand will be killed. When it hits the ground/wall, it will will be killed. An optional thing to add would be to add particle effects. Now, because this is a data pack, Minecraft temporarily gets stopped to run the calculations. After it has, Minecraft will be unpaused and the armour stand will travel instantly, making a hitscan gun. I hope this helps.
Video Link
in this video's description, he made this gun with these mechanism,
How the commands work--
if execute command can't detect air block in your aim, measure distance from you to aim and set * (a scoreboard objective) that distance
if * isn't 0, summon armor stand in front of * facing players aim.
if it detects entity 1.5 meter around armor stand, instant damage to that entity.
kills armor stand and reset scoreboard objective *
Sorry for bad english
I'm confused with measuring the distance. how can i measure distance? Thanks for reading.
This answer may be vague, in the linked video, it shows that a data pack is used. The data pack will require a right click detection system. When right-clicked, an armour stand will be summoned to the player shooting the hitscan gun. The armour stand will then travel in the direction the player is looking via the teleport command. When it hits an entity, it will do instant damage, and then the armour stand will be killed. When it hits the ground/wall, it will will be killed. An optional thing to add would be to add particle effects. Now, because this is a data pack, Minecraft temporarily gets stopped to run the calculations. After it has, Minecraft will be unpaused and the armour stand will travel instantly, making a hitscan gun. I hope this helps.