distance of another player and he is facing the other pla"> How can I do simple melee combat? | Torque Game Engine | Forums | Community | GarageGames.com

Game Development Community

How can I do simple melee combat?

by John Klimek · in Torque Game Engine · 05/04/2006 (11:36 am) · 4 replies

I'd like to have melee weapons in my game (eg. knife, baseball bat, hammer, wrench) that players can equip to kill other players. The melee combat can be as simple as "when a player is within distance of another player and he is facing the other player, he can press 'A' to attack him which will reduce his health by 50%"

Where can I even get started with something like that?

Thanks!

#1
05/04/2006 (11:43 am)
Melee resource

I think Dreamer's MMORPG tutorials also have melee. It's been a while since I checked them, though.
#2
05/04/2006 (12:47 pm)
Thanks!

However, that seems a bit complicated for simple melee combat...

Is there a simpler way to add an "attack" animation and then if the mounted model (eg. sword, bat, etc) hits another player it fires an event?

I don't need players to be stunned or shields or anything like that... (the above tutorial adds all of that and seems very complicated)
#3
05/05/2006 (7:54 pm)
For simple FPS style melee combat, just make a weapon that does a short raycast instead of making a projectile.
#4
05/05/2006 (11:31 pm)
datablock ShapeBaseImageData(KnifeImage)
{
   // Basic Item properties
   shapeFile = "~/data/shapes/knife/knife.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first  rendering.
   mountPoint = 0;
   offset = "0 0 0";
	eyeOffset = "0.04 0.25 -0.75";

	damage = 35;

	icon = "./knife.png";

   correctMuzzleVector = false;

   className = "WeaponImage";

   item = Knife;
  
   // Initial start up state
   stateName[0]                     = "Preactivate";
   stateTransitionOnLoaded[0]       = "Activate";

   // Just displaying it and that is it.
   stateName[1]                     = "Activate";
   stateSequence[1]                 = "Activate";
	stateTransitionOnTimeout[1]      = "Ready";
	stateTimeoutValue[1]             = 0.1;

	stateName[2]                     = "Ready";
	stateTransitionOnTriggerDown[2]  = "Swing";

stateName[3]                     = "SecondSwing";	
stateSequence[3]                 = "Melee";
statescript[3]	= "OnMelee";
stateTransitionOnTimeout[3]      = "Ready";
stateTimeoutValue[3]             = 1.5;
stateSound[3]		= SliceSound;

};

function KnifeImage::OnMelee(%this, %obj, %slot)
{

	%player = %obj.client.player;
   %player.setArmThreadPlayOnce("knifeslash"); // if you have a slashing animation
   %eye = %player.getEyeVector();
   %vec = vectorScale(%eye, 3);	// distance we can hit from 
   %start = %player.getEyeTransform();
   %end = VectorAdd(%start,%vec);
   %found = ContainerRayCast (%start, %end, $TypeMasks::PlayerObjectType, %player);
//   if(%found.client.team != %obj.client.team)	// Only damage enemies
//	{
//		echo("Found = "@%found@" Datablock = "@%found.getDataBlock()); 
		%mypos = %obj.getposition();
		%theirpos = %found.getposition();
		%vector = VectorSub(%theirpos, %mypos);
		%vector = VectorNormalize(%vector);
	   %found.getDataBlock().damage(%found, %obj, %vector, %this.damage, "Melee"); 
//	}
}

That should work. When you hit the button it will check for anythign that is within 3 meters of you, and damage them. You can make it team compliant by removing the commented areas.