Game Development Community

Linking combos animation (like in fighting game)

by Broken_Sword · in Torque Game Engine · 08/13/2005 (9:25 pm) · 17 replies

Hi,

I'm pretty new at this Torque coding and would like some suggestion about linking one animation to the next.
Let say that I have set up these following animation in Milkshape;
seq 100-129: Horizontal attack1
seq 130-159: Diagonal Attack1
seq 160-189: Final Blow1
seq 190-195: Kick 1

How should I start building my code so that;
when I press [Ctrl] once the character does Horizontal attack1,
when I press [Ctrl] after the first one within 200ms the character follows up with Diagonal Attack1,
when [Ctrl] is hit again within 200ms the character does the final blow.
And Kick attack can be executed ONLY after Diagonal attack 1.

Do I need to use nested if? or case-switch?

Thank you in advance for your suggestion,
-Broken_Sword-

#1
08/13/2005 (10:32 pm)
Hmm, something like the following?

(this is psuedo code)

Hattacktimer=0
Dattacktimer=0

if Ctrl_key_pressed and Hattacktimer = 0  and Dattacktimer = 0 then
   doHattack
   Hattacktimer = 200
   schedule event that sets timer to zero after Hattacktimer amount in ms has passed. (200 ms)

else 

if Ctrl_key_pressed and Hattacktimer > 0  and Dattacktimer = 0 then
   doDattack
   Dattacktimer = 200
   schedule event that sets timer to zero after Dattacktimer amount in ms has passed. (200 ms)

else

if Ctrl_key_pressed and Dattacktimer > 0 then
   doFattack
   
endif


if kick_key_pressed and Hattacktimer > 0 then
   doKick
#2
08/13/2005 (11:11 pm)
Hi David,

Thanks for your suggestion, the psuedo-code captures exactly what I wanted.
I appreciate your time in replying my post.

-Broken_Sword-
#3
08/13/2005 (11:14 pm)
You are welcome.
#4
08/16/2005 (11:32 am)
Hello.
Did you get it working?

I'd like to see other people's method of attacking this problem
#5
08/16/2005 (3:15 pm)
Hi David,

I'm still building my animations in Milkshape (I'm a softimage 4.0 Foundation owner), i'm still hitting walls in milkshape 3d.
I will try to iterate quickly a simply game to do this (without the collision boxes around the sword surely), see how this works. Then I will build a simple code out of this pseudo code (Will your name on the credit of course :) )

I'd like to see other people approaching this problem. Why I wanted to build this complex stuff? because I've seen many indie games with lacking concern in animations (which build realism in the game).

I'm aiming for complex animations like in Devil May Cry, Dynasty Warriors series, or Virtua Fighters series. I want to break habits of making complex fighting scene with only 1-2 repetitive swinging sword animation (lame isn't it?).

I will let you about my progress ... hopefully in 2-3 weeks time.
Thanks you for your interest in this, Well keep in Touch!!!


-Broken_Sword-
#6
02/12/2006 (5:05 am)
I am working on implemtenting multiple combinations into my project also, I dont understand what to do with this psuedo code. I have all of the animations ready in milkshape, and I have read Ken Finneys 3DGPAi1, but it does not cover combinations in fighting. I have heard that state machines will play a huge part in this, I have a thread about this topic, but the posts are very slow, can somebody please help me.
#7
02/12/2006 (4:17 pm)
@ David:

Hi, David How are you doing? It's been a while since we talked.
I still haven't got chance to implement the code, but i checked MUGEN, an old fighting game engine, all the combos are linked up together by finite state machine method (in which I have a littttle idea about), but i guess by doing FSM we can chained up more combos. Doing 20+ combos hit by using nested "if" might not be such a good idea. I'm not using Milkshape anymore, doing animation on milkshape is really a pain, and i don't have plenty of "patience" in stock. I'm switching to Blender, which is surprisingly not that annoying to use :)


@ Louden:
Same here, I bought both Ken Finneys books and it doesn't cover combos.
YES!!! State machine!!!!, I'm looking in to it right now. I did state machine back in UNSW, just thoeries and few hands on assignment.
I have currently 2 projects and 3 jobs. Those 2 projects are Hovercraft Racing Game with Torque and Fighting-survival kind of game which the player gains exp and after certain exp reached a new moves will be unlocked.

I'm not a good coder/script-er , I'm an Mechatronics Engineer by degree and an Illustrator for children's book by trade.
If i have something new, I'll let you guys know.

.....

I didn't think that this Torque-thing could be so HUGE, i mean, this game engine allows customisation on Camera, player, vehicles, AI, physics, Collision, animations, vehicle steering, weapon states, items properties, particles, skybox, fog distance, terrain, gui , etc, etc, etc..... I spent only $100 on the Engine but I guess that the fun would last for more than 10 years :D

Have a great week everyone!

-Broken_Sword-
#8
02/24/2006 (12:30 am)
@Broken Sword:
Wow, you go to UNSW!!! Im still in year 12, I went to the ANZAAS Youth Conference there last year and it was a blast!!! I am applying for ADFA, the Defence Force division of UNSW, in 2007.

Anyway, I have not had time to do much research into state machines but I have a forum thread up about it, waiting for responses. I think everybody is using TDN now, because I have not had a response for a long time.

I couldn't imagine the code getting really complicated. I just want Torque to trigger an animation specific animations in result of clicking the mouse button. I have plenty of animations in milkshape, with the DSQ blend exporter working (8which should take care of the fluency of the transitions between the animations), so I could point Torque to those animations for the code. I could use the same code for different classes of weaponry (like Fists, Swords, Axes) but just point the code to seperate animation for each.

I explain my theory in more depth in my thread.

http://www.garagegames.com/mg/forums/result.thread.php?qt=39365

Is this not possible? Can somebody please help me out? I think that just disguising simple code with fantastic animations would really work.

Farewell,
Louden
#9
02/24/2006 (9:47 pm)
Wow Coooll!! I wish you all the best!

I'm using TDN too, although most of the infos are still.. blank...

I had a look into the thread, but i'm guessing that the code shouldn't be too complicated.

Actually, If you managed to get this combo linking to work, write a book about it (just like ken finney) and I'll be the first to buy your book. :D

Sorry, I couldn't be much help at this point.

-Broken_Sword-
#10
03/20/2006 (5:14 am)
I think that the techniques described in this resource will address most of the requirements of this combat code.

http://www.garagegames.com/mg/forums/result.thread.php?qt=15858

It talks about 'ray-casting'. My interpretation is that when you call the attack animation a ray is cast in the vicinity of the sword.

Is it a 'null dts' model that is attached to the sword, that calls specific functions when it collides with other objects? Does anybody understand these?
#11
03/20/2006 (5:17 am)
In audition to my last post, this page breaks down the TSSsapeInstnace, which calls the ray casting, I think...

http://www.garagegames.com/docs/tge/engine/structTSShapeInstance_1_1MeshObjectInstance.php
#12
03/20/2006 (11:47 am)
Bookmarked! I'll look into it...

Thanks Louden!
#13
03/30/2006 (5:56 pm)
Hi Louden...

I had a look, but I absolutely have no idea what's going on in there... i didn't know doing combo animations would be this difficult... so.. if you have any clue... please do tell me...
#14
05/21/2006 (6:07 pm)
...I'm too dumb for this, I've given up the idea of this combo stuff... I tried to search the forums 'till my nails grew 2 inches still have no idea what's going on in Torque's animation system...
#15
05/21/2006 (6:38 pm)
Playing a simple list of animations is easy... just a crude mockup would look something like this (Not real code, just an idea what it could look like).
function swordimage::onfire(%obj... blah){

if(!%obj.comboAnim)
 %obj.comboAnim = 1;

if(%obj.comboAnim == 1)
 %obj.playThread("horizontalSlash");

if(%obj.comboAnim == 2)
 %obj.playThread("verticalSlash");

if(%obj.comboAnim == 3)
 %obj.playThread("finalSlash");

%obj.comboAnim++;

if(%obj.comboAnim > 3)
 %obj.comboAnim = 1;

}
#16
05/21/2006 (9:04 pm)
You can combine the animations like this:

in ~/server/scripts/player.cs

$attackID = 0;
$attackStartIndex = 2;
$attack[0,0]="celwave";
$duration[0,0]=1000;
$attack[0,1]="dance";
$duration[0,1]=1000;

$attack[1,0]="celsalute";
$duration[1,0]=1000;
$attack[1,1]="recoil";
$duration[1,1]=4000;
$attack[1,2]="dance";
$duration[1,2]=2000;


function serverCmdAttack(%client, %whichAttack)
{
	error("WhichAttack: ",%whichAttack);
	%client.player.schedule(0,DoAttack,%whichAttack,$attackStartIndex);
}

function Player::DoAttack( %this, %whichAttack, %index )
{
	error("%whichAttack: ",%whichAttack,"   %index: ",%index);
	if(%index < 0)
		return;
	%this.setActionThread($attack[%whichAttack,%index]);	
	%index--;
	%this.schedule($duration[%whichAttack,%index],DoAttack, %whichAttack,%index);

}


in ~/client/config.cs (for testing)
moveMap.bindCmd(keyboard, "0", "commandToServer(\'Attack\',1);", "");
moveMap.bindCmd(keyboard, "9", "commandToServer(\'Attack\',0);", "");




and upon further reflection, you can call the DoAttack sequence from the OnFire method of a melee weapon, like a sword, and pass in the handles for the sword and it's image to the DoAttack function, and use a containerRayCast technique to detect the hits.

Use something like the following, at each scheduled call of DoAttack where you want to detect a hit - you need %obj, %slot to be passed from your weapon's OnFire method, probably passed through DoAttack:
function DoHitCheck(%obj, %slot)
{
	%weapon = %obj.getMountedImage(%slot); 	//Find what weapon we are using
	// handVec is the vector coming from the weapons's "muzzle" (set the muzzlePoint of the melee weapon  
	// to be at the player's hand in the model - handVec indicates which way it points)
	%handVec = %obj.getMuzzleVector(%slot);
	%handNVec = VectorNormalize(%handVec);         // handNVec = normalized handVec
	%range = 2;                                    // length of the weapon, like a sword from hilt to tip
	%handScaled = VectorScale(%handNVec, %range);  // scale muzNVec to the distance the melee weapon reaches
	%handPoint = %obj.getMuzzlePoint(%slot);       // handPoint = the location of the player's hand
	%tip = VectorAdd(%handPoint, %handScaled);     // tip = hand point + length of weapon
	// search for just about anything that can be damaged as well as interiors
	%searchMasks = $TypeMasks::PlayerObjectType;
	// search for objects within the beam's range that fit the masks above
	%scanTarg = ContainerRayCast(%handPoint, %tip, %searchMasks, %obj);
	if(%scanTarg && !(%scanTarg.getType() & $TypeMasks::InteriorObjectType))
	{
		%target = firstWord(%scanTarg);    // a target in range was found
		%target.getDataBlock().damage(%target, %obj, VectorAdd(%target.getPosition(),%vec), $damageValue, $DamageType::Ground);
	}
}
#17
05/21/2006 (10:49 pm)
@Mr. Ken Finney & Mr. Wedge,

Thank you for your replies, I'll have a look tonight and will try to understand at what you've done here.


@Mr. Ken Finney

I bought 2 of your books and waiting for the 3rd one. Great work, Huge Thanks for doing it. The way you arranged the codes in the books can be followed without much difficulties. I'm wondering... How do you plan for programing/scripting? Do you draw block diagram or flowchart beforehand?

Greatly appreciated, thank you.


-broken_sword-