I’m working on a grapplegun type thing, and I need to detect if a property is inside the object the mouse is over. This code works as long as I don’t get the property from the mouse over. It says that the property grapple is undefined, which I guess is true, but how do I define it? How do I let it know it’s looking for that property within the hit objects of the mouseover?
Code:
if grapple in hit_obj:
if keys[leftmouse] >= 1:
toggle = True
if toggle:
target_vec = Vector(player.getVectTo(own)[1])
target_vec.magnitude = PULL_SPEED
player.setLinearVelocity(target_vec.xyz)
print(toggle)
if ‘grapple’ in hit_obj:
I use this a lot in my power passing scheme,
import bge
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner
## Get Root \/ \/ \/ \/
def get_parents(obj):
while obj.parent:
obj = obj.parent
if len(obj.children) >= own['RootChild']:
own['Root']=obj.name
own['RootChild']=len(obj.children)
## Get Root /\ /\ /\ /\
## Set Max- Apply power \/ \/
if own['Root']!="":
Root=scene.objects[own['Root']]
childList = Root.childrenRecursive
if 'Max' in own:
own['Max']=0
for item in childList:
if 'Max' in item:
if 'Capacity' in item:
own['Max']=own['Max']+item['Capacity']
for item in childList:
if 'target' in item:
if 'target' in own:
item['target']=own['target']
if 'Power' in item:
if 'Battery' in own:
if item['Power']+own['Battery']<own['Max']:
item['Power']=item['Power']+own['Battery']
if item['Power']>=own['Max']:
item['Power']=own['Max']
if 'Battery' in own:
if Root['Power']+own['Battery']<own['Max']:
Root['Power']=Root['Power']+own['Battery']
if Root['Power']>=own['Max']:
Root['Power']=own['Max']
if 'target' in own:
if own['target']!="X":
Root['target']=own['target']
get_parents(own)
Attachments
Powerandtargetpassing (1).blend (931 KB)