Game Development Community

I need hlep with the Zombie pack

by Ammon Mills · in Torque 3D Professional · 04/16/2012 (9:09 am) · 19 replies

To start out, I went to this page, http://www.garagegames.com/community/blogs/view/21353, and also created a melee weapon using http://www.garagegames.com/community/resource/view/20273/2

That being said, I am still having some problems, and hopefully some of you masterful gents can help a rookie out. Here are the following problems I am having:

UAISK
Can get a zombie to spawn, although it is always the same model, and not any of the others (the first with the mohawk).

The Zombies
When set to CritterBehavior or EscortBehavior, they just kind of float, never run. How do I get the run animation to play?

The Weapon
After following the melee weapon tutorial, it appears in UAISK, but doesn't do anything when I equip a zombie with it. I am obviously doing something wrong, but cannot figure out what. I have made a few weapons before, but wouldn't come close to calling my self adept in the process.

Any and all help(detail is especially desired) would be a blessing. Post up, or email ammonpm AT gmail.com
Thanks again.

#1
04/16/2012 (12:05 pm)
I don't use UAISK, so I can't help you with the first issue, however I would recommend not using a weapon to handle the zombies. Instead, write a function that checks the distance between the zombie and it's respective target, and if it's in range, do a raycast check to see if it can hit the target, and dish out damage accordingly.

You can easily code in the hit animation by using: %zombie.setActionThread("Attack1");
#2
04/16/2012 (12:31 pm)
Could you give me an example of the script? I haven't done any programming since college more than 10 years ago, and am very rusty with scripting.

EDIT: Got the first problem solved. Not sure what I did wrong, but redid the instructions from the first link and now I have the plethora of zombies. Although, something happened to their scale, and they are larger than the character.
#3
04/17/2012 (1:34 pm)
The size thing sounds to me like you're applying some funky scale parameter on your datablock. You do not need to resize the zombie objects as they are in line with the player by default.

This is what I use to initiate the attack on the zombie. Incorporate this into your function for range checking.

$melee_check2hit =
      $TypeMasks::VehicleObjectType |
      $TypeMasks::PlayerObjectType |
      $TypeMasks::TerrainObjectType |
      $TypeMasks::StaticTSObjectType |
      $TypeMasks::StaticShapeObjectType |
      $TypeMasks::ForestObjectType;

function Melee_Attack(%obj) {
   %name = "Attack"@getRandom(1, 2);
   %obj.setActionThread(%name);

   %eyeVec = %obj.getEyeVector();

   %startPos = %obj.getEyePoint();
   %endPos = VectorAdd(%startPos, VectorScale(%eyeVec, 2));

   %target = ContainerRayCast(%startPos, %endPos, $melee_check2hit, %obj);
   %col = firstWord(%target);

   if(%col == 0) {
      return;
   }
   
   if($Zombie::DamageFactor == 0) {
      $Zombie::DamageFactor = 1;
   }

   // Apply damage to the object all shape base objects
   if (%col.getType() & $TypeMasks::ShapeBaseObjectType) {
      %col.damage(%obj, %pos, 15*$Zombie::DamageFactor, "Slap");

      %vpos = %col.getWorldBoxCenter();
      %pushDirection = VectorSub(%vpos,%obj.getWorldBoxCenter());
      %pushDirection = VectorNormalize(%pushDirection);

      %pushVec = VectorScale(%pushDirection,1000);
      %pushVec = getwords(%pushVec,0,1);
      %col.applyImpulse(%vpos, %pushVec);
   }
}
#4
04/18/2012 (7:37 am)
Do I add this to scripts/server/weapon.cs? Not sure how to implement this.
#5
04/18/2012 (6:57 pm)
@Ammon - see this link, it shows how to resize the zombies to what ever sizes you want.

www.garagegames.com/community/resources/view/21353

It also shows how to setup the default run, walk scripts -- possibly the issue you were having with them floating. (having no run animation)

The UAISK has parameters that control the "minimum" and "max" range of a weapon ... so the melee weapon you added needed those parameters set so the can know when to run toward target to get in range or if they can try to melee the target.

In the install docs and directions, it has a template of variables to add to a new weapons (item) datablock.
#6
04/18/2012 (7:03 pm)
Here is the item datablock variables I was referring to;
datablock ItemData(melee)  
{  
...   
   //AISK Changes: Start
   //Set the max distance a bot will fire this weapon from
   ignoreDistance = 5;
   //Set the min distance a bot will fire this weapon from
   minIgnoreDistance = 0;
   //Set if this weapon uses ammo or not
   usesAmmo = false;
   //Sets how long the bot waits between firing bursts
   fireDelay = 2000;
   //Sets how long the bot holds down the trigger when firing. Use longer pulses for spray and pray type weapons.
   triggerDown = 5;
   //Sets the relative quality score of the weapon, how good is the weapon?
   //This should be set to a different value for every weapon.
   weapRating = 3;
   //The amount of ammo that bots using this weapon should start with.
   weapStartAmmo = 999;
   //AISK Changes: End        
};
#7
04/18/2012 (7:20 pm)
"Do I add this to scripts/server/weapon.cs? Not sure how to implement this. "

what u not sure?
to implement robert's melee attack?

if so then use this one:
http://tdn.garagegames.com/wiki/T3D/Tutorials/SimpleFPSTutorial/Part9
#8
04/19/2012 (9:49 am)
Let me clarify the run/walk issue I am having. They do animate, and slowly walk, although it they move faster, they kind of hover of the ground, moving faster than their animated legs. This is with the .cs files the zombies came with. I tried using your .cs files, Jeff (thanks for your tutorials, by the way. I have read and at least tried to use most of them), and they float in crucified from. Just now, I combined the stock .cs file with Jeff's .cs and now they run...but don't walk. Had one doing a moonwalk, running while moving slowly backward, kind of funny. On a plus side, they now actually chase me, which is good. And the resize is finally working.

As for the weapon, I have tried Jeff's and Robert's methods, but I have to be doing something very wrong. Would anyone be so kind as to let me email you my melee datablock and weapon.cs file so that you can briefly look it over and give me any pointers?
#9
04/19/2012 (1:36 pm)
Moonwalking is an interesting issue - I don't know if it works in COLLADA, but the old dts exporter would allow the model to automatically scale the playback speed of the run animation based on movement speed if the run animation actually moved in the 3D modelling app. So, if your run sequence actually ran forward from the origin point the engine will use that information to scale the run animation in game.

That said, the soldier was not created this way and I don't think the zombies were either.

Perhaps there is a separate walk animation in there? It's been a while since I looked at this....
#10
04/19/2012 (3:36 pm)
@Ammon -- a couple things to add, hope it helps.

the engine chooses on its own when to use the WALK or RUN animations ... its based on the objects movement speed, usually defined in the objects datablock.

my zombies either RUN or stand IDLE ... since I did nothing to lower their default speed enough to have the engine use the WALK animation. If I had done that, then I'd need to also do something to make them RUN, increasing their speed and causing the engine to play the RUN animations.

IF these were collada models, I might be asking if you tried forcing them "to center" and "ground" during the import process ... as not doing so could cause that sliding behavior, but I dont that applies in the case of the zombies.

To get it to work with UAISK requires knowing a bit more how it actually works ... (see my resource above, on how to "fix" UAISK so it doesn't resize the zombies back to their default size)

When you bring up the UAISK GUI, do the zombies show up properly there? check the weapons tab, do you have weapons assigned to them ?

try the rocket launcher, see if when assigned to them ... they start firing and so on.

then clear the weapons and just assign the MELEE weapon. (it shows up in the list, right?)

if so, then the weapon "exists" and should now be in their inventory.

(now, go back and check your console.log ... and make sure there are no syntax errors, to be 100% sure)

if all is good up to that point ... check that the variables I posted above are defined. The zombies should be closing to within 5 meters, then attack via melee.

- - - -
Personally, I renamed thier attack animation to MELEE and kick off the animation in my melee weapon scripts.

I used the sprint animations, renamed to RUN ... so when they came after me, they did so with arms out stretched -- like zombies should!

And added echo statements everywhere and checked the console log ... to see when/if the attacks where even attempted.
- - - -

#11
04/20/2012 (7:48 am)
I am not really worried about the animation, it is more or less fine for my purposes. Thanks for all the help on that, guys. I understand now, Jeff, why the always run, no more walking when using your setup.

I assigned the rocketlauncher to the zombies, it is at their feet, and they shoot me with it. I assign my melee attack with UAISK, and nothing. Tried it with my default bots, and they run to me, but that is all, no attack. Looked in the console log, and nothing seemed out of place or any errors. I think it is the weapon. I may be no good at creating them.
#12
04/20/2012 (2:45 pm)
sounds like you got it all working except for the actual onfire methods, check to see if you added a script file under scripts/server/melee.cs or such. If not, create it.

In it, should contain the onFire() code which is executed by the attack ... and a helper function to "fake" the attack.

Something like this ...
function meleeImage::onFire(%this, %obj, %slot)
{
        // kick off the attack animation
	%obj.setActionThread("melee");

        // wait 1/4 second for animation to start before doing damage
	%this.schedule(250, "Melee_Attack", %obj);
	
        //%this.playAudio(0, ZombieMelee01Sound); 
        // serverPlay3D(MeleeAttackSound, %obj.getTransform());    	
        echo("+++ meleeImage::onFire +++");
}

function meleeImage::Melee_Attack(%this, %obj)
{
    echo("+++ meleeImage::Melee_Attack +++");
	   
    %HitDistance = 5;   // default was 2 
    %DamageAmt = getRandom(5,50); // random damage, 5- 50
    %PushAmount = %DamageAmt * 100; // default was 1000       
      
    $melee_check2hit = 
     $TypeMasks::VehicleObjectType |
     $TypeMasks::PlayerObjectType |
     $TypeMasks::TerrainObjectType |
     $TypeMasks::StaticTSObjectType |
     $TypeMasks::StaticShapeObjectType |
     $TypeMasks::ForestObjectType;
     
    %eyeVec = %obj.getEyeVector();

    %startPos = %obj.getEyePoint();
    %endPos = VectorAdd(%startPos, VectorScale(%eyeVec, %HitDistance));
	  
    %target = ContainerRayCast(%startPos, %endPos, $melee_check2hit, %obj);
    %col = firstWord(%target);
   
	if(%col == 0) 
		return;
   	
	echo(%col);
	  //return the ID of what we've hit
	  
      // Apply damage to the object all shape base objects
	if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
	{
		%col.damage(%obj, %pos, %DamageAmt , "Base Melee Attack");
	  
		echo(%col.getname());

		%vpos = %col.getWorldBoxCenter();
		%pushDirection = VectorSub(%vpos,%obj.getWorldBoxCenter());
		%pushDirection = VectorNormalize(%pushDirection);

		%pushVec = VectorScale(%pushDirection,%PushAmount); // 1000 // 5000
		%pushVec= getwords(%pushVec,0,1);
		%col.applyImpulse(%vpos, %pushVec);
	}
}

make sure you execute the melee script in the execScripts.cs under scripts/server as well ... add a line like this, assuming above.
exec("./melee.cs");

and now you should see log messages as the attack onFire and Melee_Attack get initiated.

and if you have renamed the attack animation to "melee", they will also be swinging their arms at you now.
#13
04/21/2012 (12:00 pm)
Yeah Richard, I think it may be a different walk animation because my zombies do the same funny moonwalk hover thing.

I still have yet to solve my recast problem, but from what I see here, it looks like if you're going to DB route, your zombies are not getting a hold of the weapon. Check the datablock to ensure that max[melee] = 1; is in it. (Assuming of course the item Db is "melee")
#14
04/23/2012 (8:35 am)
I feel I am getting closer with your help, Jeff and Robert. I have now placed that as my melee script. What I had was close, but now exact.


EDIT: As I was going to post my melee datablock so that you guys could pick it a part. I copied and pasted it into this post I realized I forgot the semi colon on the end of the file (one of those "face-palm" moments). The attack works, but now poses a different problem. They no longer run (or walk), and just float towards me swinging, without feet moving. Also, after I am dead, they keep floating around swinging at nothing. Where in the datablock do I adapt for the animation? This probably looks a little sloppy, and I apologize for that. Any help and criticism is most welcome.

datablock ItemData(melee)
{
category = "Weapon";
className = "Weapon";
shapeFile = "art/shapes/weapons/zombieWeapon/zombieWeapon.dae";
mass = 12;
elasticity = 0.2;
friction = 0.6;
maxVelocity = "15.0";

pickUpName = "Zombie Weapon";
image = meleeImage;
description = "Zombie Weapon";

ignoreDistance = 5;
minIgnoreDistance = 0;
usesAmmo = false;
fireDelay = 2000;
triggerDown = 5;

max[melee] = 1;
};

datablock ShapeBaseImageData(meleeImage)
{

shapeFile = "art/shapes/weapons/zombieWeapon/zombieWeapon.dae";
mountPoint = 0;
eyeOffset = "0 0 0"; // 0.46=right/left 0.5=forward/backward, -0.5=up/down

className = "WeaponImage";
item = melee;

stateName[0] = "Activate";
stateTransitionOnTimeout[0] = "Ready";
stateTimeoutValue[0] = 0.5;
stateSequence[0] = "Activate";
stateSound[0] = DrawWeaponSound;

stateName[1] = "Ready";
stateTransitionOnTriggerDown[1] = "Fire";

stateName[2] = "Fire";
stateTransitionOnTimeout[2] = "PostFire";
stateTimeoutValue[2] = 0.8;

stateAllowImageChange[2] = false;
stateScript[2] = "onFire";
stateSound[2] = meleeFireSound;

stateName[3] = "PostFire";
stateTransitionOnTimeout[3] = "Ready";
stateTimeoutValue[3] = 0.1;
stateAllowImageChange[3] = false;

};

#15
04/23/2012 (5:17 pm)
so you made progress though, now they attack ... go back and check the animation scripts, step #4 in my how-to you reference above.

the ::onLoad() scripts to be specific and verify each of your animations syntax is still good. I bet the run animations are not being applied for syntax reasons ... since the melee animation works now.

:POINT BEING: I've "lost" many hours trying to fix problems which ended up being syntax mistakes, like extra or missing punctionation. Using TORSION eliminated 60-80% of that, except those where logic is off but syntax still "valid"/compiles.

So I suggest using TORSION, so you can pre-compile all of the scripts before it even runs the game ... i.e it helps you debug your scripting. there is a free version/demo

otherwise, the syntax you listed all looks fine

** EDIT: removed my email address **




#16
04/25/2012 (10:33 am)
Did you get that email, Jeff?
#17
04/27/2012 (9:00 pm)
OK to get them to not float around attacking you either "depending on you" stop their animation when they move or make it so the zombie doesn't move while attacking.

as for when your dead and they are still attacking try setting the range on where they fire
ignoreDistance = 5;
minIgnoreDistance = 0;
to

ignoreDistance = 1;
minIgnoreDistance = 0;


that should do the trick
#18
04/27/2012 (11:30 pm)
@Ammon

I downloaded the art pack and see its been updated to "Zombie Art Pack for 1_2" and now I see the confusion with the scripts.

one problem is by renaming Attack1, you also need to change it down below or it remains cyclic --

%this.renameSequence("Attack1", "melee"); 

   %this.setSequenceCyclic("Attack1", "0");

Just move the rename commands to the bottom of the file and you are fine. If it helps, I added a comment on my how to page -- in case anyone else tries to use it with the updated Art pack as well.

You could also change the fireDelay variable to like 5000 (5s) instead of the default 2s, that would slow down thier attacking.
//Sets how long the bot waits between firing bursts  
   fireDelay = 2000;

But I thought the UAISK onFire code checked to see if the target was dead ... If not, im sure there was been a post in the forums on it.
#19
04/30/2012 (8:47 am)
Jeff, you are a genius. It works how it should now, more or less. He runs, swipes, then runs some more, then swipes again. I die, he stops animation. The one tweak it would need to polish it out perfect, when he attacks, if I am moving back at the same time, he swings while floating, but then runs again at the end of the animation. Kind of like what you said, Adam, I need to make it so they don't move while attacking. Any pointers?

And thank you all very much for helping.