Game Development Community

Swinging my sword

by Rojalee · in Torque Game Engine · 04/21/2006 (10:08 am) · 7 replies

Okie dokie,

I have a char, who is carrying around this big sword, and no way to swing it.

I tried one of the resources, but it didn't help me out.

I'm not looking to implement an entire melee system, I just want him to swing it.

Any ideas on how to do this.

(PS i'm a total clusterf**k so, easier the beter)

#1
04/21/2006 (10:55 am)
Does your character have a swing animation?
#2
04/21/2006 (11:07 am)
Has anyone here seen Kung Pow?

**'...Swinging my chain, just swinging my chain...'**

Anyhow, basically you'll need to:

- Create the swinging animation for the player
- Call the animation in script perhaps in the onFire state of your sword script
- Make a slight modification to the source code to allow a cell animation to play and not be cancelled out by other animations

If you're running a fairly unmodified copy of torque press ctrl-w or ctrl-s and you'll notice the Orc character play some animations. They're called cell animations and you might want to track them down in script and see how they work, then you can use that info and apply it to your swinging sword. The rest of what you'll need is in the melee resource.
#3
04/21/2006 (11:41 am)
Hmm now thats a very nice theoretical answer.
Anyone have the nuts and bolts.

The only 2 things i've added to TGE are my player and my sword.

so it's very basic copy.

I have the animation already.
- I can probably copy the onFire state from the crossbow.cs and tweak it?

the source code mods are probably way beyond me, even though I know where they are located.
they Datablock for the cell animations is in player.cs (the original one)

where is the ctrl-w or ctrl-s defined though. I would need to add one (lets say letter K for kill) and that would call up the swinging animation?

ah getting deeper grasshopper.
#4
04/21/2006 (12:07 pm)
I have found the xbow::onfire and it looks like this.

// function BroadswordImage::onFire(%this, %obj, %slot)
// {
//    %projectile = %this.projectile;
//
   // Decrement inventory ammo. The image's ammo state is update
   // automatically by the ammo inventory hooks.
//   %obj.decInventory(%this.ammo,1);

   // Determin initial projectile velocity based on the 
   // gun's muzzle point and the object's current velocity
//   %muzzleVector = %obj.getMuzzleVector(%slot);
//   %objectVelocity = %obj.getVelocity();
//   %muzzleVelocity = VectorAdd(
//      VectorScale(%muzzleVector, %projectile.muzzleVelocity),
//      VectorScale(%objectVelocity, %projectile.velInheritFactor));

   // Create the projectile object
//   %p = new (%this.projectileType)() {
//      dataBlock        = %projectile;
//      initialVelocity  = %muzzleVelocity;
//      initialPosition  = %obj.getMuzzlePoint(%slot);
//      sourceObject     = %obj;
//      sourceSlot       = %slot;
//      client           = %obj.client;
//   };
//   MissionCleanup.add(%p);
//   return %p;
// }

I commented it all out after I pasted it to my broadsword.cs.

I notice this function looks like it actually Creates the Bolt for the xbow.
So...any idea how I can change this to call a player animation. After I do this, I will figure out the damage part.
#5
04/22/2006 (3:41 am)
Your best bet is to get the code for the melee resource and plough your way through that, as suggested above. I don't think anybody is going to recreate all that code here step by step just to talk you through it. I could be wrong, but I doubt it...
#6
04/22/2006 (4:41 am)
If the sword swing animation is just something that's animated for your arms and upper torso, flag it as a blend on export and you can play it with the playThread function easily. No crazy source code dealings or nothing.
#7
04/24/2006 (3:53 am)
@Dave.

ok going to the melee resource.

@Paul

the sword and person are different models.....
will search for the playThread function and see what I can do.

Thanks.