# Blender Game Engine: RayCast to get a point

I'm making an fps game and I have a gun which I want to have a laser sight (similar to this: https://imageshack.com/f/jxdscn2857sj)
I've tried to do this using the logic editor but I realised I would most likely need to use python. So basically, is there a way - like in Unity - to get a point by raycasting?

Here's an image of what I want:

• Image link doesn't work for me. – muhuk Sep 4 '15 at 6:46
• please post the image in your question. External links are not good and can (as in this case) expire. – Monster Sep 4 '15 at 7:22
• @Monster okay I've added the image – Jacob_ Sep 4 '15 at 15:16
• @muhuk okai I've added the image – Jacob_ Sep 4 '15 at 16:30

The hitPosition of a Ray sensor will give you the coordinate of were a ray hits an object.

To use it, add a Ray sensor to the object and connect it to a Python controller.

Create a text block and enter the following script to access the hitPosition.

import bge

controller = bge.logic.getCurrentController()
owner = controller.owner
ray = owner.sensors["Ray"]

#world coordinates of where ray hit object
ray.hitPosition


Finally, enter the script name in the Python controller.