Announcement

Collapse
No announcement yet.

[Code] Deadly Zombie (Updated)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [Code] Deadly Zombie (Updated)

    ey up

    i was just messing around with ai stuff and quickly came up with this, its a very simple zombie type thing. if you can make use of it feel free.
    it will just stand there untill it sees the player, then it will follow, making no allowance for obsacles, all it can see is the players tasty brains.
    no need for pathnodes or navmesh as it moves directly to the player location.

    the code as it is now it takes health away from the player on contact, health goes no lower than 1.

    here are some examples of other things you can do to the player pawn.
    replace the line P.Health --;
    with 1 or more of the following
    (assuming your player pawn is extended from UTPawn)

    P.CustomTimeDilation = 0.1; //slows down time
    P.Destroy(); //kills the player
    P.DoJump(true);
    P.Gasp();
    P.GroundSpeed *=2; //double walking speed
    P.InitRagdoll();
    P.SetDrawScale(0.5); //half size
    P.SetPhysics(PHYS_Flying); //make me fly
    P.SetPhysics(PHYS_Spider); // i can climb walls!
    P.ForceCrouch();

    if you have question please ask on this thread
    more than likely someone can give you a better answer than i can.

    have fun getting them stuck places.

    TestZombiePawn.uc
    Code:
    class TestZombiePawn extends UTPawn
    Placeable;
    
    var Pawn P; // variable to hold the pawn we bump into
    
    // members for the custom mesh
    var SkeletalMesh defaultMesh;
    var MaterialInterface defaultMaterial0;
    var AnimTree defaultAnimTree;
    var array<AnimSet> defaultAnimSet;
    var AnimNodeSequence defaultAnimSeq;
    var PhysicsAsset defaultPhysicsAsset;
    
    simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
    {
    	Mesh.SetSkeletalMesh(defaultMesh);
    	Mesh.SetMaterial(0,defaultMaterial0);
    	Mesh.SetPhysicsAsset(defaultPhysicsAsset);
    	Mesh.AnimSets=defaultAnimSet;
    	Mesh.SetAnimTreeTemplate(defaultAnimTree);
    
    }
    
    simulated event Bump( Actor Other, PrimitiveComponent OtherComp, Vector HitNormal )
    {
     `Log("Bump");
    
         Super.Bump( Other, OtherComp, HitNormal );
    
    	if ( (Other == None) || Other.bStatic )
    		return;
    
      P = Pawn(Other); //the pawn we might have bumped into
    
    	if ( P != None)  //if we hit a pawn
    	{
                if (P.Health >1) //as long as pawns health is more than 1
    	   {
                 P.Health --; // eat brains! mmmmm
               }
            }
    }
    
    defaultproperties
    {
    	defaultMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
    	defaultAnimTree=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    	defaultAnimSet(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    	defaultPhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
    
    	Begin Object Name=WPawnSkeletalMeshComponent
    		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    	End Object
    
    	RagdollLifespan=180.0
    	
    	ControllerClass=class'TestZombieBot'
    
    
    }
    TestZombieBot.uc
    Code:
    class TestZombieBot extends GameAIController;
    
    var Pawn thePlayer; //variable to hold the target pawn
    
    simulated event PostBeginPlay()
    {
    	super.PostBeginPlay();
    
    }
    
     event SeePlayer(Pawn SeenPlayer) //bot sees player
    {
              if (thePlayer ==none) //if we didnt already see a player
              {
    		thePlayer = SeenPlayer; //make the pawn the target
    		GoToState('Follow'); // trigger the movement code
              }
    }
    
    state Follow
    {
    
    Begin:
    
    		if (thePlayer != None)  // If we seen a player
    		{
    
    		MoveTo(thePlayer.Location); // Move directly to the players location
                    GoToState('Looking'); //when we get there
    		}
    
    }
    
    state Looking
    {
    Begin:
      if (thePlayer != None)  // If we seen a player
    		{
    
    		MoveTo(thePlayer.Location); // Move directly to the players location
                    GoToState('Follow');  // when we get there
    		}
    
    }
    
    defaultproperties
    {
    
    }
    Other AI's from me
    http://forums.epicgames.com/showthread.php?t=801590
    http://forums.epicgames.com/showthread.php?t=799268
    http://forums.epicgames.com/showthread.php?t=798718

    September Update:

    Code:
    class TestZombiePawn extends UTPawn
    Placeable;
    
    var Pawn P; // variable to hold the pawn we bump into
    var() int DamageAmount;   //how much brain to munch
    
    simulated function PostBeginPlay()
    {
       super.PostBeginPlay();
    
       //wake the physics up
       SetPhysics(PHYS_Falling);
    }
    
    //over-ride epics silly character stuff
    simulated function SetCharacterClassFromInfo(class<UTFamilyInfo> Info)
    {
    	Return;
    }
    
    simulated event Bump( Actor Other, PrimitiveComponent OtherComp, Vector HitNormal )
    {
     `Log("Bump");
    
         Super.Bump( Other, OtherComp, HitNormal );
    
    	if ( (Other == None) || Other.bStatic )
    		return;
    
      P = Pawn(Other); //the pawn we might have bumped into
    
    	if ( P != None)  //if we hit a pawn
    	{
                if (TestZombiePawn(Other) != None)  //we hit another zombie
                {
                   Return; //dont do owt
                }
                else
                {
                 //use a timer so it just takes health once each encounter
                 //theres other better ways of doing this probably
                SetTimer(0.1, false, 'EatSlow');
                }
         }
    }
    
    simulated function EatSlow()
    {
        P.Health -= DamageAmount; // eat brains! mmmmm
    
        if (P.Health <= 0)//if the pawn has no health
         {
         P.Destroy();  //kill it
         }
    }
    
    defaultproperties
    {
    	Begin Object Name=WPawnSkeletalMeshComponent
    		AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_Human'
    		SkeletalMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK_CH_IronGuard_MaleA'
    		AnimSets(0)=AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale'
    		PhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Mesh.SK_CH_Corrupt_Male_Physics'
    	End Object
    
    	RagdollLifespan=180.0 //how long the dead body will hang around for
    
    	AirSpeed=200
    	GroundSpeed=200
    
    	ControllerClass=class'TestZombieBot'
    	bDontPossess=false
    
    	DamageAmount=10
    }
    the bot works fine still

    #2
    Awesome, that's a great start for anybody looking to make a creature AI.

    Comment


      #3
      Super! I'd like to clone Ur brain, and have Ur productivity too

      Comment


        #4
        very simple Thanks a lot tegleg

        Comment


          #5
          hi please answer my simple question of 2
          1.where to put the 2 uc files?
          2.how to make it putted in the unreal editor form content browser?
          thanks

          Comment


            #6
            hwoarang, you're going to have to read up on setting up a simple mod project in unreal.

            http://www.hourences.com/an-entire-simple-udk-game/

            After that, it should be clear where to place these.

            Comment


              #7
              i read .i find the pawn class in content browser .but it is can not be place able .plese help,thanks

              Comment


                #8
                hi

                i use udk 2010 11 version
                i place the pawn in the editor
                testzombie pawn.test in editor .nothing out .
                can somebody help?thanks

                Comment


                  #9
                  double click the pawn to bring up its properties
                  click AI
                  untick 'dont possess'

                  sorry i should have said that before

                  Comment


                    #10
                    thanks for the code,although i had to alter it a little to work in the september 2010 issue.also to make it a little more zombie like i copied the origional AnimSet'CH_AnimHuman.Anims.K_AnimHuman_BaseMale' and then set all the anim sequnce rates to .5 and replaced the animset in your code.also replaced the physics asset with one that has the arms and head set to physics instead of animation.resulting in slower and floppy zombies.once again,thanks.

                    Comment


                      #11
                      Thanks, Tegleg, it works nicely.
                      I see that you have two states that basically loop each other. i usually use
                      Code:
                      if(isinstate(blah))
                      {gotostate(blah);}
                      to loop inside of a tick.

                      of course, there is a autostate I use for the pawn to go back to that's not looped.
                      Just an FYI.
                      EDIT: Strike that last comment. Works fine without ticking the state.

                      Comment


                        #12
                        so do you not add the pawn using the Actor Factory??

                        i added the pawn using the Actor Factory but its invisible/doesn't spawn and earlier in the post you were talking about changing the pawn's properties

                        Comment


                          #13
                          I used actor factory and it worked. Did you:

                          use 'begin level' trigger--- actor factory---attach pathnode & object variable,
                          and run it, that should work.

                          Comment


                            #14
                            select the pawn in the actor browser
                            right click on your level (3d view) > add testzombiepawn here
                            double click the pawn
                            under the AI tab
                            untick 'dont possess'

                            should also work with the actor factory

                            Comment


                              #15
                              yupp i added the zombie the way you do it, i hope lol, should be okay though.

                              aha I finally found it in the actor browser but unfortunately I cant place the actor :0(



                              i copied everything word for word but i saved it in a folder called UDK_CustomZombie though(if that helps)

                              class TestZombiePawn extends UTPawn;

                              var Pawn P;

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

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

                              }

                              simulated event Bump( Actor Other, PrimitiveComponent OtherComp, Vector HitNormal )
                              {
                              `Log("Bump");

                              Super.Bump( Other, OtherComp, HitNormal );

                              if ( (Other == None) || Other.bStatic )
                              return;

                              P = Pawn(Other);

                              if ( P != None) //if we hit a pawn
                              {
                              if (P.Health >1)
                              {
                              P.Health --; //take away the pawns health
                              }
                              }
                              }

                              defaultproperties
                              {
                              defaultMesh=SkeletalMesh'CH_IronGuard_Male.Mesh.SK _CH_IronGuard_MaleA'
                              defaultAnimTree=AnimTree'CH_AnimHuman_Tree.AT_CH_H uman'
                              defaultAnimSet(0)=AnimSet'CH_AnimHuman.Anims.K_Ani mHuman_BaseMale'
                              defaultPhysicsAsset=PhysicsAsset'CH_AnimCorrupt.Me sh.SK_CH_Corrupt_Male_Physics'

                              Begin Object Name=WPawnSkeletalMeshComponent
                              AnimTreeTemplate=AnimTree'CH_AnimHuman_Tree.AT_CH_ Human'
                              End Object

                              RagdollLifespan=180.0

                              ControllerClass=class'TestZombieBot'


                              }
                              class TestZombieBot extends GameAIController;

                              var Pawn thePlayer;

                              simulated event PostBeginPlay()
                              {
                              super.PostBeginPlay();

                              }

                              event SeePlayer(Pawn SeenPlayer) //bot sees player
                              {
                              if (thePlayer ==none) //if we didnt already see a player
                              {
                              thePlayer = SeenPlayer;
                              GoToState('Follow');
                              }
                              }

                              state Follow
                              {

                              Begin:

                              if (thePlayer != None) // If we seen a player
                              {

                              MoveTo(thePlayer.Location); // Move directly to the player
                              GoToState('Looking');
                              }

                              }

                              state Looking
                              {
                              Begin:
                              if (thePlayer != None) // If we seen a player
                              {

                              MoveTo(thePlayer.Location); // Move directly to the player
                              GoToState('Follow');
                              }

                              }

                              defaultproperties
                              {


                              }

                              Comment

                              Working...
                              X