Object to Raycast collision point

Hey! Its been a while. I hope you’re all doing well. I was wondering if anyone knows how to make an object copy the location of the point of contact of a ray sensor. Not for a moment, but constantly.

A good example is to think of an in-world crosshair in a third person shooter. Lets say I had a ray casting out of the front of my players gun, I want to be able to have a plane with a crosshair texture on it copy the point on any surface that the ray is hitting, and have it dynamically change as I look around.

I have seen this in an OLD bge game, cant find it now. Thanks in advance for your help guys!

always--------python


import bge
from mathutils import Vector
cont = bge.logic.getCurrentController()
own = cont.owner
Object2 = own.scene.objects['Object2Name']

#set end point of ray here
End = own.worldTransform*Vector([0 , 0, -5]) 

Start = own.worldPosition
Prop = ""
ray = own.rayCast( End, Start, 0, Prop, 0,0,0)
if ray[0]:
    #you hit something
    Object2.worldPosition = ray[1]
    #uncomment to align object2 Z axis by ray hitnormal 
    #Object2.alignAxisToVect(ray[2], 2, .1)

note - if this is shooting off a armature child bone objects child - you may have to move to a predraw callback

PERFECT. Thank you so much!