I'm a beginner in UnrealScripting. we are using UDK to make a game for our project and so far everything else is done, the only thing that is left is AI.. after going through some online tutorials and I created a simple AI that when sees the player , moves up to the player and when the AI has reached certain amount of distance it shoots at the player.
I did this based on a tutorial... and this is how I did it. i made a class MyAIController extends AIController; and then made a class Myenemy that extends from UDK pawn and i have made this as a placeable actor (is this a good practice ?)
So far I got the AI to follow me when ever it spots me, how ever it doesn't shoot me when it gets close and for when i shoot it.. it doesnt die.. its like the pawn is immune to the shots.. i can't even see the weapon i have given it.. but if i shoot it for a while it will drop the weapon and will stop moving o_O !.
these are my questions.. i decided to post them in a single thread instead of multiple ones..
1. What am i doing wrong in the first bit (code posted at the end)
2.is it possible to make the AI characters perform an animation before going to the chase state (i want them to do the throat slit anim )
if so how do i do that ? i can't seem to get my head around it
3. right now my pawns are placeable actors.. is this a good way to spawn them ? or should i use kismet ? if so how do i spawn multiple enemies at the same time ? and how do i make sure that kismet doesn't spawn a new one when i killed them all ?
Any help would be appreciated! .
AIcontroller Code
MyEnemy CodeCode:class MyAIController extends AIController; var Actor target; var() Vector TempDest; event Possess(Pawn inPawn, bool bVehicleTransition) { super.Possess(inPawn, bVehicleTransition); Pawn.SetMovementPhysics(); } simulated event GetPlayerViewPoint(out vector out_Location, out Rotator out_Rotation) { // AI does things from the Pawn if (Pawn != None) { out_Location = Pawn.Location; out_Rotation = Rotation; //That's what we've changed } else { Super.GetPlayerViewPoint(out_Location, out_Rotation); } } //I'm adding an default idle state so the Pawn doesn't try to follow a player that doesn' exist yet. auto state Idle { event SeePlayer (Pawn Seen) { super.SeePlayer(Seen); target = Seen; GotoState('Follow'); } Begin: } state Follow { ignores SeePlayer; function bool FindNavMeshPath() { // Clear cache and constraints (ignore recycling for the moment) NavigationHandle.PathConstraintList = none; NavigationHandle.PathGoalList = none; // Create constraints class'NavMeshPath_Toward'.static.TowardGoal( NavigationHandle,target ); class'NavMeshGoal_At'.static.AtActor( NavigationHandle, target,32 ); // Find path return NavigationHandle.FindPath(); } Begin: if( NavigationHandle.ActorReachable( target) ) { //FlushPersistentDebugLines(); //Direct move MoveToward( target,target ); } else if( FindNavMeshPath() ) { NavigationHandle.SetFinalDestination(target.Location); FlushPersistentDebugLines(); NavigationHandle.DrawPathCache(,TRUE); // move to the first node on the path if( NavigationHandle.GetNextMoveLocation( TempDest, Pawn.GetCollisionRadius()) ) { //DrawDebugLine(Pawn.Location,TempDest,255,0,0,true); //DrawDebugSphere(TempDest,16,20,255,0,0,true); MoveTo( TempDest, target ); } } else { //We can't follow, so get the hell out of this state, otherwise we'll enter an infinite loop. GotoState('Idle'); } if (VSize(Pawn.Location - target.Location) <= 256) { GotoState('Shoot'); //Start shooting when close enough to the player. } else { goto 'Begin'; } } state Shoot { function Aim() { local Rotator final_rot; final_rot = Rotator(vect(0,0,1)); //Look straight up Pawn.SetViewRotation(final_rot); } Begin: Pawn.ZeroMovementVariables(); Sleep(1); //Give the pawn the time to stop. Aim(); Pawn.StartFire(1); Pawn.StopFire(1); GotoState('Idle'); } DefaultProperties { }
Code:class MyEnemy extends UDKPawn; event PostBeginPlay() { super.PostBeginPlay(); //AddDefaultInventory(); //GameInfo calls it only for players, so we have to do it ourselves for AI. } DefaultProperties { Begin Object Name=CollisionCylinder CollisionHeight=+44.000000 end object Begin Object class=SkeletalMeshComponent Name=SandboxPawnSkeletalMesh SkeletalMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA' AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale' AnimTreeTemplate= AnimTree'CH_AnimHuman_Tree.AT_CH_Human' HiddenGame=FALSE HiddenEditor=FALSE End Object Mesh=SandboxPawnSkeletalMesh Components.Add(SandboxPawnSkeletalMesh) ControllerClass=class'Mygame.MyAIController' InventoryManagerClass=class'Mygame.SandboxInventoryManager' bJumpCapable=true bCanJump=true GroundSpeed=200.0 //Making the bot slower than the player }




! .
Reply With Quote


Bookmarks