Here is my badguy1 and badguy1Controller classes. Thanks to the owner for providing this on the internet.
Code:
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 int BumpDamage;
var SkeletalMeshComponent MyMesh;
var bool bplayed;
var Name AnimSetName;
var bool AttAcking;
var () array<NavigationPoint> MyNavigationPoints;
defaultproperties
{
BumpDamage = 3.0;
Speed=75
//AnimSetName="ZombieAttackBiteSeq"
AttAcking=false
defaultMesh=SkeletalMesh'Mypackage2.Zombie'
defaultAnimTree=AnimTree'Mypackage2.ZombieAnimTree'
defaultAnimSet(0)=AnimSet'Mypackage2.ZombieAnimSetFinal'
defaultPhysicsAsset=PhysicsAsset'EternalCrisis_Characters.Female.Human_Athletic_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'Mypackage2.Zombie'
AnimSets(0)=AnimSet'Mypackage2.ZombieAnimSetFinal'
AnimTreeTemplate=AnimTree'Mypackage2.ZombieAnimTree'
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
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
}
function SetAttacking(bool atacar)
{
AttAcking = atacar;
}
simulated event Tick(float DeltaTime)
{
local AITestPawn gv;
super.Tick(DeltaTime);
MyController.Tick(DeltaTime);
foreach CollidingActors(class'AITestPawn', gv, 200)
foreach VisibleCollidingActors(class'AITestPawn', gv, 100)
{
if(AttAcking && gv != none)
{
if(gv.Health > 0)
{
//Worldinfo.Game.Broadcast(self, "Colliding with player : " @ gv.Name);
gv.Bump(self,CollisionComponent,vect(0,0,0));
}
}
}
}
simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
{
Mesh.SetSkeletalMesh(defaultMesh);
//Mesh.SetMaterial(0,defaultMaterial0);
Mesh.SetPhysicsAsset(defaultPhysicsAsset);
Mesh.AnimSets=defaultAnimSet;
Mesh.SetAnimTreeTemplate(defaultAnimTree);
}
And badguy1Controller class
Code:
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 = 2000
//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);
}
}
}
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)
{
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);
}
}
Bookmarks