import bge import random #running from some empty with always true scene = bge.logic.getCurrentScene() item_list = [] node_list=[] # human =survivor,player hunted by zombies human_list = [] zombie_list = [] # civilians will follow survivors after save civilian_list = [] survivor_list = [] msg_list = ["Nothing Here","Something Near","Something Found","Attacking"] for i in scene.objects: if ("item" in i): if i["item"]=="human": if i not in human_list: human_list.append(i) if i["item"]=="node": if i not in node_list: node_list.append(i) for h in scene.objects: if ("hunting" in h) and ("Status" in h): if ("type" in h): if h["type"]=="zombi": tgg = sorted(human_list, key=lambda obj: obj.getDistanceTo(h))[0] h.alignAxisToVect(h.getVectTo(tgg)[1], 1, 0.1) d = h.getDistanceTo(tgg) h.alignAxisToVect([0.0,0.0,1.0],2,1) #Zaxys align h["hunting"] = 0 if d>90 else 1 if d > 70 else 2 if d>3 else 3 h["Detect"] = msg_list[h["hunting"]] visn = rayCast(tgg, h, 50,"",0, 1, 0) if visn[0] not in human_list: tgn = sorted(node_list, key=lambda obj: obj.getDistanceTo(h))[0] h.alignAxisToVect(h.getVectTo(tgg)[1], 1, 0.1) dn = h.getDistanceTo(tgn) h.alignAxisToVect([0.0,0.0,1.0],2,1) #Zaxys align elif visn[0] in human_list: h.alignAxisToVect(h.getVectTo(tgn)[1],1,0.1) h.alignAxisToVect([0.0,0.0,1.0],2,1) #if the target is behind a wall, i would add a script here for "hunt" node_list[map] instead of target, using a generated Ray,not a brick # #if h["Status"] == "active": #this 'IF' is added cause in the game there could be some ["typeVar"] of the same ["type"] hunting obj, like more fast, more strong,different attack/action type. # hunting = 0 no action, hunting =1 idle stand, walking, hunting = 2 run to target, hunting = 3 stop and attack if h['Status'] == "active": if h["hunting"] > 0: Rev = random.randint(0,10) if Rev%3 == 0: h.applyMovement((0, 0.1, 0), True) h['action'] = "walk" else: h['action'] = "idlestand" if h["hunting"] > 1: h.applyMovement((0, 0.2, 0), True) h['action'] = "run" if h["hunting"] > 2: h.applyMovement((0, -0.200001, 0), True) h['action'] = "attack"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question