For my pawn, I created a state that ’ locks on ’ to a target. The state works and all, but once the state is committed and goes through all the code, i cannot move my pawn around at all.
No warnings or errors come up in the Log and I’m not sure what to do to enable control over my pawn again( though still possessed )
This is how the state is called, simple exec function to start all of this
exec function ToggleCombat()
{
GoToState('EngageCombat');
}
And now here is the state code, it does not loop.
state EngageCombat
{
function CheckForEnemies()
{
if(BladePawn(Pawn) != None)
{
foreach WorldInfo.AllPawns(class'BladeAIPawn', PendingTarget)
{
if(PendingTarget != LockTarget)
{
`log(" did fast trace");
if(FastTrace(PendingTarget.Location, Pawn.Location)) // if nothing inbetween
{
if(PendingTarget.Health > 0)
{
LockedTargets.AddItem(PendingTarget); // add to lock targets
`log(" the pending target is "$PendingTarget);
CountEnemies();
}
}
}
}
}
}
function CountEnemies()
{
if(BladePawn(Pawn).Health > 0 && BladePawn(Pawn) != None)
{
AmountTargets = LockedTargets.Length;
if(AmountTargets == 1 || AmountTargets > 1)
{
bCombat = true; // there is an enemy
LockOnTarget();
}
else if(AmountTargets == 0 || AmountTargets < 0)
{
GoToState('');
bLockedOn = false;
}
}
}
function LockOnTarget()
{
bLockedOn = true;
`log(" lock target = " $ LockedTargets[0]);
LockTarget = LockedTargets[0]; // find the first enemy in the array
BladeHUD(myhud).SetTargetIcon(LockTarget.FaceIcon,LockTarget.Level,LockTarget.Health);
LockRotation();
}
function LockRotation()
{
if(bLockedOn)
{
Pawn.SetRotation(rotator(LockTarget.Location - Pawn.Location));
Pawn.SetViewRotation(rotator(LockTarget.Location - Pawn.Location));
DrawDebugLine(Pawn.Location,LockTarget.Location,0,0,255,true);
Pawn.ZeroMovementVariables();
`log("pawn is locked on target");
return;
}
}
Begin:
CheckForEnemies();
}
I think it has something to do with the Pawn::SetRotation() function maybe? Im not quite sure, any help anyone??? Appreciate it.