Game Development Community

Best way to damage a player?

by Justin P Greer · in Game Design and Creative Issues · 08/29/2010 (1:14 pm) · 6 replies

Ok So I am making a Zombie game and I am now looking into how I want the zombie to attack the player.
I have come up with 2 idea's but I dont know what would work.

Ok first way. Simple
- Give AI Melee feature
This feature I dont want because I want the zombie's to have NO weapon. Unless there is a way to do this with no weapon added to the melee feature.

Secound - Questionable!!!!!!
- Added some attack animations to the zombie models. Then create a function in the ai script to where when the ai get within range of the Player it is attacking the the Attack animation is trigger ( to easy )

Now here is what I was thinking, When the Attacking zombie swings and collides with the player then a percentage of health is lost. I am not for sure How I could do this.

Which way should I do this and or is there any resources out the for attacking zombies with no weapons?

#1
08/30/2010 (12:18 pm)
Well, this is how I would do it.

Pseudo code:

function AIDatablock::OnCollision(%this, %obj, %col) /* This function is executed when the AI collides with a player */
{
   if(%col.getDatablock().getName() $= "PlayerDatablock") /* Check if we collided with a player */
   {
      %col.damage(%obj, %pos, 20, "Zombie"); /* If it's a player, lets give him 20 damage */
      //some code to play attack animation here
   }
}
#2
08/30/2010 (2:12 pm)
Could also use Classname, useful if you've multiple player types rather than a single datablock .
%checkclass = %col.getclassname();
   if(%checkclass $= "player")
	{
             //science goes here
    }
#3
08/30/2010 (5:16 pm)
@Tuomas
That's what I was planning on doing, I just didn't know if there was a better way of doing it. I was also thinking of something more on the lines of what Steve just added but with a random damage percentage between little to a lot.

I was even going to go as far as adding something in the code to adjust the damage in relation to where the collision was made. Kinda like the ballistic part of the weapons.cs 9 when a head shot damge = 100% and when a body shot damage = 30 or some random number)

My main question is though. Is the collision way the best way/only way or is there another way. I really like the collision idea.
#4
08/30/2010 (5:29 pm)
Another way ... you could do a short range raycast attack.

1 Beastie checks if target is in 2 metres/yards
2 if(yes) Beastie does raycast forwards from eyenode and plays an attack animation
3 if raycast hit's a Player, roll for damage/location

Damage varying with location is taken care of when from the player's end, in player.cs(scripts) and you can add body parts ... I think in stock only headshots are covered, I've added legs with halves the damage easy enough.
#5
08/30/2010 (5:32 pm)
Thanks Steve that is more what I was looking for. The first Idea was just that, a Idea on paper.. I am sure once a take a look at how the head shot function works I could grasp at least the basic knowledge needed to get started on the right path to adding limbs to the parts of the model that could be damaged. but really for right now the basic will work just fine.
#6
08/30/2010 (6:44 pm)
Quote:
This feature I dont want because I want the zombie's to have NO weapon. Unless there is a way to do this with no weapon added to the melee feature.
One alternative is to mount an invisible "dummy" image that fires an invisible short ranged/lived projectile and let it do damage.

Anything mentioned here already are all viable means to an end. I would suggest experimenting with each method to find the one that works the best for you.

I saw mention of location dependent damage... looks like my script example got stripped out when the FPS Kit became the FPS Example and Template -- my fault probably but was thinking that I would've left it in the FPSExample at least. The stock code uses a percentage calculation to determine damage location, and these percentages are setup in the player datablock. The engine does the work but the entry point for script to use this would be in scripts/server/player.cs at function Armor::damage(). Torque considers three body parts: the head, torso, and legs. The torso and leg regions are divided up into four (left/right front/back) quadrants. The head consists of 9 (left/middle/right back/middle/front)quadrants. Find the applyDamage() line in Armor::damage() and replace it with this:
// Locational damage, damage amount modifiers - this is NOT true locational
// damage, but only a "best guess" based on a hitbox percentage calculation
// done by the engine.
%location = %obj.getDamageLocation(%position);
%bodyPart = getWord(%location, 0);
%region = getWord(%location, 1);
//echo("\c4DAMAGELOCATION:  bodyPart = "@ %bodyPart @" || REGION = "@ %region);
// BODYPARTS:  HEAD | TORSO | LEGS
// REGION (legs/Torso):  front_left | front_right | back_left | back_right
// REGION (head):  left_back   | left_middle   | left front
//                 middle_back | middle_middle | middle_front
//                 right_back  | right_middle  | right_front
switch$ (bodyPart)
{
   case "head":
      %damage = %damage*2; // double damage for headshots
   case "torso":
   case "legs":
      %damage = %damage/2; // half damage for legs
}
%obj.applyDamage(%damage);
That will give you basic locational damage. Anything more complicated (or detailed) than this would require the addition of actual hitbox locations to the engine.

In the stock code you'll notice that the %location variable is hardcoded to "body" and is passed on as a parameter to onDeath() where it isn't being used. There is a way of using this location information to trigger specific animations when a player is killed, but that is another topic ;)