2
$\begingroup$

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: enter image description here

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

1 Answer 1

1
$\begingroup$

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.

Logic editor

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .