Downloadlink .blend file:
http://www.file-upload.net/download-8235314/IFanky-Laserpointer.blend.html
Laser.py Script:
from bge import logic as GameLogic
from mathutils import Vector
c = GameLogic.getCurrentController()
own = c.owner
space = 0.003
# sensors
laser = c.sensors[« laser »]
ray = c.sensors[« ray »]
# actuator
spawn = c.actuators[« spawn »]
if laser.positive and ray.positive:
# Get info
pos_vec = Vector(ray.hitPosition)
normal_vec = Vector(ray.hitNormal)
# make object
spawn.instantAddObject()
laser_dot = spawn.objectLastCreated
target = GameLogic.getCurrentScene().objects[‘Empty.lasertarget’]
# position hole
laser_dot.alignAxisToVect(normal_vec.xyz, 2, 1)
normal_vec.magnitude = space
laser_dot.worldPosition = (pos_vec + normal_vec).xyz
target.worldPosition = (pos_vec + normal_vec).xyz
Voir sur youtube