hay guys! in need of a little help I am, hhhmmmmm.
so I am trying to set up a script to make an enemy wander around semi randomly. I have an empty with the property ‘empt’ as a child of the enemy, and a cube on an inactive layer. there is also a nav mesh with the property ‘nav’.
the idea is to have the script get the enemies location, adjust the x and y coordinates by up to 4units. shift the z up a bit, and use these new coordinates as the origin for a raycast.
the raycasts down to see if it hits an object with the ‘nav’ property (the navmesh) and if so, returns hit location. the child empty is placed at that location, and a raycast is cast from about the point of the enemies eyes to the empty to see if it with its ‘empt’ property is the 1st thing hit. if so, the enemy has sight of that location and then sets an added copy of that cube from the other layer, to the location of the empty. the cube is set as the target for a steering actuator, and the enemy ‘wanders’ to it.
my code looks as fallows:
import bge
import logic
import mathutils
import vector
import randomcont = bge.logic.getCurrentController()
own = cont.owner
pos = vector(own.worldPosition)
node = scene.objectsInactive[‘Cube’]
targ = scene.addobject(node,pos)
target = none
targetfound = false#get the enemies child empty for use in target checking
for ob in own.children
if ‘empt’ in obj: child = objmyx = pos[0]
myy = pos[1]
myz = pos[2]eyez = myz + 0.2
'# wander destination finding module
while targetfound == false
'# think I made a mistake here, this setup might cause coordinates that are not within 4 of the enemy right?
testx = random.randint(0,4)
testy = random.randint(0,4)
testz = myz + 2inver = random.randint(0,1)
if inver == 0
testx += myx
else
testx += -myxinver = random.randint(0,1)
if inver == 0
testy += myy
else
testy += -myyreypos = vector(testx,testy,testz)
newz = myz - 1
dest = (testx,testy,newz)obhit, hitloc, fase = ray_cast(dest, reypos, 3, nav, 0, 1)
if obhit != none
child.location(hitloc)
else
continuereypos = (myx,myy,eyez)
obhit, targloc, fase = ray_cast(hitloc, reypos, 5, empt)if obhit == none
continue
else
targ.location(targloc)
targetfound = truecont.actuators[‘wand’].target = targ
can anyone tell me what I’m doing wrong? I think that when the cube from the inactive layer is made the value of a variable at the top of the script, that the cube would be added to the active layer at that point. that or the cube would be added whenever the variable is called? but the cube does not appear and the enemy never moves from where he starts. I’m not sure what part isn’t working. thank you in advance.