Shooting gallery

I’d like to script something where the player has a crosshair and when clicking it shoots a projectile based on an object in the world

For example the player sees the game from an iso standpoint but is controlling a turret. Wherever he clicks on the terrain, the turret would shoot at that location.

I’m using the code from the Machine gun in the FPS tutorial, and I’m trying to figure out how to modify it to register the raycasts properly.

Basically I need to know how to register a location in the world clicked from a cursor, and change the aim of the gun to hit that location.