PDA

View Full Version : Custom BotAI Problem



Ghoul
03-02-2010, 09:01 AM
Hi, I use the custom made Bot from xnasorcerer in my project. The problem is, there is no relative Function, to set a Fire at function in Kismet for him and i want him to use his weapon. Now he attacks "with his body".... Please could anyone help me i have no idea how to manage it.... i m trying to fix this for 2 days now :( (i used the search function etc.)


AI Controller class:

class Badguy1Controller extends AIController;

var Badguy1 MyBadguy1Pawn;
var Pawn thePlayer;
var Actor theNoiseMaker;
var Vector noisePos;

var () array<NavigationPoint> MyNavigationPoints;
var NavigationPoint MyNextNavigationPoint;

var int actual_node;
var int last_node;

var float perceptionDistance;
var float hearingDistance;
var float attackDistance;
var int attackDamage;

var float distanceToPlayer;
var float distanceToTargetNodeNearPlayer;

var Name AnimSetName;

var bool AttAcking;
var bool followingPath;
var bool noiseHeard;
var Float IdleInterval;

defaultproperties
{
attackDistance = 50
attackDamage = 10
perceptionDistance = 1000

AnimSetName ="ATTACK"
actual_node = 0
last_node = 0
followingPath = true
IdleInterval = 2.5f

}

function SetPawn(Badguy1 NewPawn)
{
MyBadguy1Pawn = NewPawn;
Possess(MyBadguy1Pawn, false);
MyNavigationPoints = MyBadguy1Pawn.MyNavigationPoints;
}

function Possess(Pawn aPawn, bool bVehicleTransition)
{
if (aPawn.bDeleteMe)
{
`Warn(self @ GetHumanReadableName() @ "attempted to possess destroyed Pawn" @ aPawn);
ScriptTrace();
GotoState('Dead');
}
else
{
Super.Possess(aPawn, bVehicleTransition);
Pawn.SetMovementPhysics();

if (Pawn.Physics == PHYS_Walking)
{
Pawn.SetPhysics(PHYS_Falling);
}
}
}

function Tick(Float Delta)
{
//if(IsInState('Attack'))
//{

//}

}

state Idle
{

event SeePlayer(Pawn SeenPlayer)
{
thePlayer = SeenPlayer;
distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
if (distanceToPlayer < perceptionDistance)
{
//Worldinfo.Game.Broadcast(self, "I can see you!!");
GotoState('Chaseplayer');
}
}

Begin:
Worldinfo.Game.Broadcast(self, "!!!!!!! idle !!!!!!!!");

Pawn.Acceleration = vect(0,0,0);
MyBadguy1Pawn.SetAttacking(false);

Sleep(IdleInterval);

//Worldinfo.Game.Broadcast(self, "!!!!!!! Going to FollowPath !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
followingPath = true;
actual_node = last_node;
GotoState('FollowPath');

}

state Chaseplayer
{
Begin:

MyBadguy1Pawn.SetAttacking(false);
Pawn.Acceleration = vect(0,0,1);

while (Pawn != none && thePlayer.Health > 0)
{
Worldinfo.Game.Broadcast(self, "I can see you!!");

if (ActorReachable(thePlayer))
{
distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
if (distanceToPlayer < attackDistance)
{
GotoState('Attack');
break;
}
else //if(distanceToPlayer < 300)
{
MoveToward(thePlayer, thePlayer, 20.0f);
if(Pawn.ReachedDestination(thePlayer))
{
GotoState('Attack');
break;
}
}
}
else
{
MoveTarget = FindPathToward(thePlayer,,perceptionDistance + (perceptionDistance/2));
if (MoveTarget != none)
{
//Worldinfo.Game.Broadcast(self, "Moving toward Player");

distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
if (distanceToPlayer < 100)
MoveToward(MoveTarget, thePlayer, 20.0f);
else
MoveToward(MoveTarget, MoveTarget, 20.0f);

//MoveToward(MoveTarget, MoveTarget);
}
else
{
GotoState('Idle');
break;
}
}

Sleep(1);
}
}

state Attack
{
Begin:
Pawn.Acceleration = vect(0,0,0);
MyBadguy1Pawn.SetAttacking(true);
while(true && thePlayer.Health > 0)
{
//Worldinfo.Game.Broadcast(self, "Attacking Player");

distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
if (distanceToPlayer > attackDistance * 2)
{
MyBadguy1Pawn.SetAttacking(false);
GotoState('Chaseplayer');
break;
}
Sleep(1);
}
MyBadguy1Pawn.SetAttacking(false);
}


auto state FollowPath
{
event SeePlayer(Pawn SeenPlayer)
{
thePlayer = SeenPlayer;
distanceToPlayer = VSize(thePlayer.Location - Pawn.Location);
if (distanceToPlayer < perceptionDistance)
{
//Worldinfo.Game.Broadcast(self, "I can see you!!");
noiseHeard = true;
followingPath = false;
GotoState('Chaseplayer');
}
}

Begin:

while(followingPath)
{
MoveTarget = MyNavigationPoints[actual_node];

if(Pawn.ReachedDestination(MoveTarget))
{
//WorldInfo.Game.Broadcast(self, "Encontrei o node");
actual_node++;

if (actual_node >= MyNavigationPoints.Length)
{
actual_node = 0;
}
last_node = actual_node;

MoveTarget = MyNavigationPoints[actual_node];
}

if (ActorReachable(MoveTarget))
{
//distanceToPlayer = VSize(MoveTarget.Location - Pawn.Location);
//if (distanceToPlayer < perceptionDistance / 3)
// MoveToward(MoveTarget, MyNavigationPoints[actual_node + 1]);
//else
MoveToward(MoveTarget, MoveTarget);
}
else
{
MoveTarget = FindPathToward(MyNavigationPoints[actual_node]);
if (MoveTarget != none)
{

//SetRotation(RInterpTo(Rotation,Rotator(MoveTarget. Location),Delta,90000,true));

MoveToward(MoveTarget, MoveTarget);
}
}

Sleep(1);
}
}

AI class:

class Badguy1 extends UTPawn
placeable;

// members for the custom mesh
var SkeletalMesh defaultMesh;
//var MaterialInterface defaultMaterial0;
var AnimTree defaultAnimTree;
var array<AnimSet> defaultAnimSet;
var AnimNodeSequence defaultAnimSeq;
var PhysicsAsset defaultPhysicsAsset;

var Badguy1Controller MyController;

var float Speed;

var SkeletalMeshComponent MyMesh;
var bool bplayed;
var Name AnimSetName;
var AnimNodeSequence MyAnimPlayControl;

var bool AttAcking;

var () array<NavigationPoint> MyNavigationPoints;

defaultproperties
{
Speed=80
AnimSetName="ATTACK"
AttAcking=false

defaultMesh=SkeletalMesh'My_AnimatedMeshes.ske_Bad guy1'
defaultAnimTree=AnimTree'My_AnimatedMeshes.aTree_B adguy1'
defaultAnimSet(0)=AnimSet'My_AnimatedMeshes.ani_Ba dguy1'
defaultPhysicsAsset=PhysicsAsset'My_AnimatedMeshes .ske_Badguy1_Physics'


Begin Object Name=WPawnSkeletalMeshComponent
bOwnerNoSee=false
CastShadow=true

//CollideActors=TRUE
BlockRigidBody=true
BlockActors=true
BlockZeroExtent=true
//BlockNonZeroExtent=true

bAllowApproximateOcclusion=true
bForceDirectLightMap=true
bUsePrecomputedShadows=false
LightEnvironment=MyLightEnvironment
//Scale=0.5
SkeletalMesh=SkeletalMesh'My_AnimatedMeshes.ske_Ba dguy1'
AnimSets(0)=AnimSet'My_AnimatedMeshes.ani_Badguy1'
AnimTreeTemplate=AnimTree'My_AnimatedMeshes.aTree_ Badguy1'
End Object

mesh = WPawnSkeletalMeshComponent

Begin Object Name=CollisionCylinder
CollisionRadius=+0041.000000
CollisionHeight=+0044.000000
BlockZeroExtent=false
End Object
CylinderComponent=CollisionCylinder
CollisionComponent=CollisionCylinder

bCollideActors=true
bPushesRigidBodies=true
bStatic=False
bMovable=True

bAvoidLedges=true
bStopAtLedges=true

bisplayer=false

LedgeCheckThreshold=0.5f

}

simulated function PostBeginPlay()
{
super.PostBeginPlay();
//if (Controller == none)
// SpawnDefaultController();
SetPhysics(PHYS_Walking);
if (MyController == none)
{
MyController = Spawn(class'Badguy1Controller', self);
MyController.SetPawn(self);
}

//I am not using this
//MyAnimPlayControl = AnimNodeSequence(MyMesh.Animations.FindAnimNode('A nimAttack'));
}

function SetAttacking(bool atacar)
{
AttAcking = atacar;
}



simulated event Tick(float DeltaTime)
{
local UTPawn gv;

super.Tick(DeltaTime);
//MyController.Tick(DeltaTime);


//foreach CollidingActors(class'UTPawn', gv, 200)
foreach VisibleCollidingActors(class'UTPawn', gv, 100)
{
if(AttAcking && gv != none)
{
if(gv.Name == 'MyPawn_0' && gv.Health > 0)
{
//Worldinfo.Game.Broadcast(self, "Colliding with player : " @ gv.Name);
gv.Health -= 1;
gv.IsInPain();
}
}
}
}

simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
{
Mesh.SetSkeletalMesh(defaultMesh);
//Mesh.SetMaterial(0,defaultMaterial0);
Mesh.SetPhysicsAsset(defaultPhysicsAsset);
Mesh.AnimSets=defaultAnimSet;
Mesh.SetAnimTreeTemplate(defaultAnimTree);

}