Game Development Community

Melee Combat

by Brian Lococo · in Technical Issues · 06/30/2004 (10:12 am) · 29 replies

I am currently doing the AI part of a game project based on Gladitorial combat. I am having a hard time finding a place to start in order to implement a melee style bot. Any suggestions would be appreciated.
Thanks.

About the author

Recent Threads

  • Strings as arrays?
  • Page «Previous 1 2
    #1
    06/30/2004 (11:03 am)
    Oddly enough this is a common problem when doing AI for Melee combat. The trick is to have the combat as a kind of turn based affair.

    When a player or enemy starts a combat move, a virtual round should begin, where you calculate what the AI should do i.e. does the AI block the attack or get pounded on.

    To maintain the image of realtime combat you should give the player time to block the attack (if you have a block button) or implement an autoblock if the player is facing the right direction but not pressing any buttons (as in some games out there like the jedi knight series).

    Tougher melee AI enemies would simply have a higher chance to block meaning the player would need more hidden bonuses such as a sword of hacking that behind the scenes has a +20% chance to hit above whatever base value you are using.

    Difficulty levels can be adjusted by up'ing or lowering the AI's chance to block (this also has the added illusion of making the AI look smarter)

    "That damned dread knight keeps anticipating my moves" :o)

    Start by deciding the base rules for the melee combat. Is it a close range affair, does the players character auto block if they have a high defence rating etc etc.
    #2
    06/30/2004 (12:20 pm)
    Thanks for the reply! Well, the design for the AI is completely done, it is more implementation details that im having trouble with. Setting up something like the virtual round you have described is exactly what we are trying to accomplish. Basically, my first task is going to get the bot to track the player in some form of a "Look At" algorithm. Should this be implemented in the aiPlayer.cs or rather inside the actual engine code. I did happen to come across some pathfinding tutorials, but they dealt with waypoints and not the player data.

    Just so you know, this project is for a Final Project, which we had 1 month to do the design and technical documents and have 2 months to implement the game. We all just started looking at the torque engine just a month ago, so I am very unfamiliar with it (aka NOOB). I am sure there will be several posts by myself and my teammates in the next 2 months :)

    Thanks for your help
    #3
    07/08/2004 (2:08 pm)
    I have AI that works with the RW melee system. They attack, block, and randomly move around the other player.

    Here is a melee resource:
    www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5377

    Use this method to make a bot look at a specific object.
    %bot.setAimObject(%player);

    Edit: If you need any more help, I have some AI code I can post.
    #4
    07/19/2004 (10:00 am)
    I'm interesting about the AI code, would you please post it? Thanks.
    #5
    07/25/2004 (11:34 pm)
    Here the basic attackcode, add this somewhere in your AI think loop.

    %this = your AI player
    %target = your AI player's targetobject
    %pos = %this.getPosition();
                   %pos2 = %target.getPosition();
                   %vec = VectorSub(%pos2, %pos);
                   %vec = VectorNormalize(%vec);
                   %vec = VectorScale(%vec, VectorDist(%pos, %pos2));
                   %newPos = VectorAdd(%pos, %vec);
                   %searchResult = containerRayCast(%pos, %newPos, $TypeMasks::PlayerObjectType, %this);
                   %foundObject = getword(%searchResult,0);
                   if(%foundObject == %target)
                   {
                      %this.setWaypoint(%newPos);
                      %this.setImageTrigger(0,true);
                      %this.setImageTrigger(0,false);
                   }
    #6
    07/29/2004 (12:50 am)
    @Josh:

    Have implemented the melee resource above, everything seems OK so far.

    But when I fire the sword, the animation doesn't fully show up, it just switch to the start frame of h1swing, h1slice and so on!

    I've grabbed the orc dts and dsq from the RW without any success, anyone has the same problem?
    #7
    08/05/2004 (9:49 am)
    Are you in first person view or third person? First person the animation doesn't show up at all pretty much, but third person should show up relatively smoothly. Hope that helps.
    #8
    08/06/2004 (12:29 pm)
    The problem been solved! Cause I put the code in wrong place. Thanks anyway.
    #9
    01/05/2008 (12:55 am)
    Hey steven, I oso tried taking the dsq for sword swinging to implement for my player. When i fire it just keep repeating the swingin action. It only stop when i walk. Do u have that problem?

    Also, how did u get the sword to collide with a player and get damage? I am currently stuck at it...

    Thanks
    #10
    01/09/2008 (1:07 pm)
    @rushh:

    There's a number of ways you could do this, such as adding a collision mesh to the blade of the sword and having on onCollide() effect with the sword to:
    Check if the sword is hitting a player that isn't myself.
    Check if the enemy is blocking.
    Then if those both result properly, deal x damage to the player.

    Though I think the most simple thing to do would be to have it shoot a projectile that isn't rendered with a lifetime of around 100ms and a shooting delay of 1000ms or so (the time it takes to swing the sword down) that would deal the damage of the sword instead. This of course means that you would need the crosshair to be centered on the target and you can't just slice them anywhere along the swords path.
    #11
    01/10/2008 (7:04 am)
    I tested with a itemData() of a sword without mountin it to a player. I mean the sword is spawn on the ground. It was able to detect it if a AIPlayer or player collide with it.

    I understand that you need the following datablock to mount your sword to the player.

    datablock ShapeBaseImageData( SwordImage )
    {
    	shapeFile = "~/data/shapes/sword/sword.dts";
       
    
        projectile = SwordProjectile ;
        projectileType = Projectile;
       
    	emap = true;
    
    
        // Specify mountPoint & offset for 3rd person, and eyeOffset for first 
        // person rendering.
    
        mountPoint = 0;
        eyeOffset = "0.1 0.4 -0.6";
    
    
    // all the neccessary firing codes
    
    
    
    
    };

    So continuing below to a collision code that i said earlier i put the shapeBaseImageData datablock above. So I just add it. But now it can detect the collision with the AIPlayer now that the sword is on the player hand. Is there some missing codes i am missing?
    #12
    01/10/2008 (2:23 pm)
    Ok so if I have you right, you are able to have the sword in the players hand and it is able to swing to do a player animation and it's mounted movement. It can then collide with players through that animation and register it's doing so? If that's true then...

    1) Add a Global variable that get's set to true during the attack state of the player and false again either on the end of the state or a certain amount of time later. $isAttacking, for example.
    2) Now, in the sword's onCollide() script add the following to ensure the sword will only deal damage whilest being swung.
    if ($isAttacking == false)
    return
    3) Get the target of the sword collision, check to make sure it isnt the player, else return, also if it turns out it is colliding with the player, you may want to tweak your animations.
    4) Get the target again, and %target.applyDamage(#) Where # is however much that specific sword hits for.

    And that'd be about it...I hope this is right! ;D
    #13
    01/10/2008 (11:57 pm)
    I am so sorry...there is a typo error in my previous post. I actually can't make it can detect the collision with the AIPlayer now that the sword is on the player hand. Is there some missing codes i am missing?

    I have this datablock

    datablock ShapeBaseImageData( SwordImage )
    {	
    shapeFile = "~/data/shapes/sword/sword.dts";       
    projectile = SwordProjectile ;    
    projectileType = Projectile;   	
    emap = true;    // Specify mountPoint & offset for 3rd person, and eyeOffset for first     
                           // person rendering.    
    mountPoint = 0;    
    eyeOffset = "0.1 0.4 -0.6";// all the neccessary firing codes
    };

    So I just create a collision function..like this

    function SwordImage::onCollision(%this,%obj,%col )
    {	
    if(%col.getClassName() $= "AIPlayer")
    {
    //do damage
    }
    };


    But it didnt work. I am not sure what is wrong.
    #14
    01/11/2008 (6:54 am)
    ShapeImages have no collision implemented in them.

    This is the same reason why you can see the sun flare effects through your weapon (there was a post about that recently).
    #15
    01/11/2008 (7:01 am)
    Ugh... sorry I keep forgetting to be helpful!

    What you should do is decide where damage should start (relative to the player) and where it should end. Think of this as the start and end point of the TIP of the sword only don't start way at the top or all the way at the bottom of the swing. The reason is you will then perform a raycast between these two points to determine your collision.

    You could make this a lot more complex by adding special marker nodes to your weapons that let you programmatically query the weapon for these test points. Or even do multiple tests during the animation (so that you can take the whole swing into account).

    If it was easier to post images here I'd make a nasty paint image to show you what I mean.

    Just pick two points along the swords arc when you think it is most likely to collide with enemies and raycast between those points at the moment you what to deal damage. You could even use the time of collision along the ray to set a delay for the damage to take effect.
    #16
    01/11/2008 (6:51 pm)
    Gah, I feel dumb. I forgot that ShapeImages are done on the client side only, aren't they... Since that doesn't work, you may want to use Brian's idea.
    #17
    01/12/2008 (3:14 am)
    Hi... i just heard that we need the engine folder to do the damageStart and damageEnd thingy which is in the .cc and .h file. So far now, i am not a Torque licensee and i do not have the engine folder. So i just can't do the damageStart and damageEnd stuff just using scripting language meaning only .cs file?
    #18
    01/12/2008 (6:53 am)
    I don't understand what you are saying.

    When you say "damageStart and damageEnd" are you referring to the two points I was talking about?

    If so then you can still do a simplified form! Just pick ANY two points out in front of the player that are likely to collide with the enemy. Use either a horizontal, vertical or diagonal line just in front of the player.

    If you need help we can work this out.

    You can do a LOT in just Torque Script.
    #19
    01/12/2008 (8:48 am)
    Yes, i was referring to the damageStart and damageEnd.

    I guess the usage of containerRayCast is as below

    %searchMasks = $TypeMasks::PlayerObjectType | $TypeMasks::StaticShapeObjectType;
        // search for objects within the damage rays that fit the masks above
        %scanTarg = ContainerRayCast(%startvec, %endvec, %searchMasks, %slot);

    Im not sure what is the value of the %startvec and %endvec. Is it a vector value? If its true, i just take the player vector position as damageStart? And another vector which is further up horizontally as the damageEnd?
    #20
    01/13/2008 (2:35 am)
    Tried to do a horizontal line in front of the player just by adding vectors together. But i am not sure whether i am doing the right thing. Any example?
    Page «Previous 1 2