import bge
from mathutils import Vector
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
#if target not set get target from scene objects
if type(own['Target']) is str:
own['Target']=bge.logic.getCurrentScene().objects[own['Target']]
# if you have a target object localize it
else:
# Localize the target point
local = own['Target'].worldPosition-own.worldPosition
local = own.worldOrientation.inverted()*local
own['Read']=str(local)
if local.z>0:
#it's in front
# because local +Z is front :D
#Next is a cone :D
if (abs(local.y)-local.z)<.1:
#inside cone
bge.render.drawLine(own.worldPosition+(own.worldOr ientation*Vector([0,1,1])),own.worldPosition+(own.worldOrientation*Vector([0,10,10])),(0,1,0))
bge.render.drawLine(own.worldPosition+(own.worldOr ientation*Vector([0,-1,1])),own.worldPosition+(own.worldOrientation*Vector([0,-10,10])),(0,1,0))
else:
#outside cone
bge.render.drawLine(own.worldPosition+(own.worldOr ientation*Vector([0,1,1])),own.worldPosition+(own.worldOrientation*Vector([0,10,10])),(1,0,0))
bge.render.drawLine(own.worldPosition+(own.worldOr ientation*Vector([0,-1,1])),own.worldPosition+(own.worldOrientation*Vector([0,-10,10])),(1,0,0))
main()
Attachments
LocalCone.blend (479 KB)