I posted this on the mailing list but I haven't had any help so far so I'll post it here too.
I'm writing some very basic ai that just needs to move towards an enemy when it sees it and then start attacking. It does this fine but only the first time. For example if you let it reach you then run away, it just stands there and won't start walking towards you again even though the MoveToward function is called again. The class extends scriptedcontroller. This is the relevant code:
I have checked that it does go back into the hunting state and runs the code at the begin label after enemy moves out of range. But for some reason the MoveToward function has no effect after the first time it's called. Strangely enough using MoveTo works fine but it's not really useful since the enemy will be constantly moving. What could be causing this strange problem?
I'm writing some very basic ai that just needs to move towards an enemy when it sees it and then start attacking. It does this fine but only the first time. For example if you let it reach you then run away, it just stands there and won't start walking towards you again even though the MoveToward function is called again. The class extends scriptedcontroller. This is the relevant code:
Code:
state Hunting { function Timer() { If(enemy==none) { GotoState('idling');//just in case enemy is gone } else if((VSize(enemy.Location-pawn.location)<Perverted (Pawn).MeleeRange) && (FastTrace(enemy.location, Pawn.location)))//if enemy is within melee range and not behind a wall start attacking { GotoState('MeleeAttacking'); } else { SetTimer(1, false);//if not check again later } } begin: log("now hunting"); SetTimer(1, false); MoveToward(enemy, enemy,,false); } state MeleeAttacking { function Timer() { If(enemy==none) { GotoState('idling');//just in case enemy is gone } else if((VSize(enemy.Location-pawn.location)>Perverted (Pawn).MeleeRange) && (FastTrace(enemy.location, Pawn.location)))//if enemy is now out of melee range, hunt them { GotoState('hunting'); } else { SetTimer(1, false);//if not check again later } } begin: log("now melee attacking"); Pawn.Acceleration=vect(0,0,0); SetTimer(1, false); }
Comment