Game Development Community

Zelda Melee - swordfight

by Ed Johnson · in Torque Game Engine · 03/11/2005 (12:38 pm) · 7 replies

I've seen a few resources on melee fighting, and Ive seen a sword model somewhere.

Anyone have any kind of swordfighting implemented in their TGE?

#1
03/11/2005 (1:01 pm)
RealmWars has a melee component, and there have been a number of topics made about doing it. Most of the projects have been fighting games, and when the creators realize how difficult it is to create the next Soul Calibur, they decide to go play Soul Calibur instead.

Since Zelda-style combat isn't reflective of localized damage, the current resources should work rather well. Then again, I haven't tried them. I've just read other's comments on how well they worked for their system.
#2
03/11/2005 (1:11 pm)
I haven't read much of the current works on melee and localized damage, but I don't think it is that hard, really. I'll have to implement such thing for our next project, and I got it all laid out already.

As seen in the collision meshes, you can export special mesh nodes with your DTS models to perform certain tasks. The exporters know nothing about collision there are just nodes and meshes, and the code decides how to load them, so adding custom hitboxes using the collision mesh code as reference wound't take much time.

Since our game won't feature weapons (all weapons will be part of the character models), all damage will be generated form hitbox collisions. I'll use the animation "trigger" system to control at which points of the animation a hitbox will deal damage, and how much damage is dealt. Defensive boxes use the trigger value to control how much damage they absorv, adding support for defensive stances.

When an offensive hitbox hits a passive hitbox, it'll deal damage to the passive hitbox' owner. With some extra work it may be possible to figure out the hitbox movement direction based on the animation, and use that to apply impact forces. It's also possible to use another trigger to control damage properties (like fire, electricity, poison, etc).

Buuut... back to the current project... we need money first...
#3
03/11/2005 (1:16 pm)
Heck I wouldnt even need localized damage, just torso damage.

I think a fun little adventure demo with a character running around with a big sword, swinging it at little monsters would be great... hmmmm... I should try this
#4
03/11/2005 (2:45 pm)
Well, if it's that simple, you don't even need code changes to spank some bots, or other players.

Bind this function to a key:

function attack(%val)
{
  $mvTriggerCount3 = %val;  
}

Now defind this function in your player class namespace. In the starter.fps mod, this would be Armor. Note that the function already exists in player.cs in the starter.fps mod.

function Armor::onTrigger(%this, %obj, %triggerNum, %val)
{
  %attackRadius = 1.5;
  %minDot    = 0.65;
  %damage = 1;

  if (%triggerNum == 3 && %val) {
        InitContainerRadiusSearch(%obj.getPosition(), %radius, $TypeMasks::PlayerObjectType);
        while(( %targetObject = ContainerSearchNext() ) > 0 )
       { 
          //Skip itself
          if (%targetObject == %obj)
             continue;            

          //Calculate the dot product
          %direction = VectorSub(%targetObject.getWorldBoxCenter(), %obj.getPosition());
          %direction = VectorNormalize(%direction);
          %dot = VectorDot(%direction, %obj.getForwardVector());

          //Skip object if it's angle is too great
          if (%dot < %minDot)
             continue;
          
          //Apply damage & impulse
          %targetObject.applyDamage(%damage);
          %targetObject.applyImpulse(%targetObject.getPosition(), %direction);
       }
  }
}

There might be some errors above, but you get the idea. What the code above does is look for other player objects in front of the current player, and apply damage and impulse to them. I used the trigger stuff because it works properly in multiplayer. Then you do some extra code to adjust hit frequency and such things.
#5
03/11/2005 (3:22 pm)
Is this taken from the melee resource?
#6
03/23/2005 (10:43 pm)
@Ed Johnson: No that doesn't look like it's taken from that melee resource, I think realm wars actually tested collision with the model against players and dealt damage very differently

@Manoel Neto: Thanks for this resource! This really helped alot.
If anyone else does use it though,

I found one small error (which is probably obvious to most poeple, but took me awhile to realize)

InitContainerRadiusSearch(%obj.getPosition(), %radius, $TypeMasks::PlayerObjectType);

should be

InitContainerRadiusSearch(%obj.getPosition(), %attackRadius, $TypeMasks::PlayerObjectType);

since %attackRadius was the name of the variable you declared above.
Thanks again for this!!
#7
03/24/2005 (1:19 pm)
Thanks, I ended up getting the RealmWars melee resource finally working.