Hi all
In my game I have one annoying visual bug that is a bit beyond me- I know what is causing it (roughly) but I have no idea how to fix it. Here are the two chunks:
The first finds the nearest AI player and simply nudges itself away from it to avoid crashes:
Radar_Emitter = ow.sensors["Radar"]
if Radar_Emitter.positive:
targetList = [tar for tar in Radar_Emitter.hitObjectList if 'racer' in tar]
minValue = 400
for tar in targetList:
distanceTo = ow.getDistanceTo(tar)
if distanceTo < minValue:
locked_target = tar
minValue = distanceTo
ow["current_Target"] = locked_target
(dist, glob, loc) = ow.getVectTo(ow["current_Target"])
ow.alignAxisToVect(-glob, 1, 0.006)
The second (donated to me by MarcoIT) banks the AI towards the target (an object in the scene used for navigation):
node = target
NP = node.position
OP = ow.position
vec = NP - OP
up = Vector((0,0,1))
cross = vec.cross(up).normalized()
target = NP + cross *10 # the distance to the node
vec = target - OP
ow.alignAxisToVect(vec, 1, 0.05)
ow.alignAxisToVect(up, 2, 0.02)
vecLoc=ow.getVectTo(target)[2]
vx, vy, vz = vecLoc
velRot = 0.05
ow.applyRotation((0, vx*velRot, 0), 1)
Now, both work really well…in isolation. What happens in game is that they fight against each other, and AI objects ‘jitter’ as they switch between alignments (as far as I can tell). If I disable the line in the first chunk…
ow.alignAxisToVect(-glob, 1, 0.006)
…the jitter stops. Is there a way to combine both these bits to smooth things out, or am I barking up the wrong tree?
Thanks for your time
Paul