Game Development Community

AIPlayer trigger in Animation not setting off

by Clint S. Brewer · in Torque Game Engine · 03/21/2005 (4:25 pm) · 11 replies

I have a custom Hand to Hand combat system that relies on triggers in the animation. I've been using this on my main player for a while with no problems, but I'm trying to let my AIPlayer use the same system and I'm running into problems.

in the animation, there is a trigger set with code # 6

when that trigger fires in the animation, a script function is called, this is when the Hand to hand attack check should be done.

I've set a break point in the code and this works fine for the player, but the trigger is never set for my aiplayer.

in particular the code that I've modified is here in player.cc
at the top of void Player::updateActionThread()

I've added this bit of code:
if(isServerObject())
   {
     //CLINT  spell casting animation specific.
     //game specific controlled by server
	if(mShapeInstance->getTriggerState(6)) 
	{
		//We are powering up a magical spell
		Con::executef(mDataBlock,2,"onSpellStartCharge",scriptThis());
	}
	if(mShapeInstance->getTriggerState(7)) 
	{
		//We cast a magical spell
   		Con::executef(mDataBlock,2,"onSpellCast",scriptThis());
	}
   }

neither of those cases are hitting for the ai player...

I'm in the process of debugging this, but if anyone has run into the same sort of problem before I'd love to hear about it!


thanks,
Clint

#1
03/21/2005 (4:55 pm)
Debuging a bit further it looks like animateTriggers isn't being executed for the ai player...investigating...
#2
03/21/2005 (5:31 pm)
Hmm well I'm a bit stumped right now. I do have the trigger set in the animation, verified that with the showtool pro demo. It's there and should be firing off as far as I can tell.

I suppose I could switch the player character to be the creature and verify that the attack works there, that' wouldn't be a bad idea. here goes..
#3
03/21/2005 (5:38 pm)
And guess what, it doesn't work for my main player either, must be a problem with the animation.

feeling less stumped now! :)
#4
03/21/2005 (10:14 pm)
And the problem was no ground transform in the animation. I know I've run into that one before.

solution(for 3dsmax exporter):
set a couple keyframes on the bounding box, make sure that ignore ground transform is not checked in the dts sequence helper

Monsters are much scarier when they can hurt you.
#5
03/22/2005 (7:48 am)
So the problem was that without having ground transforms the triggers in the animation did not fire, but the animation still played?
#6
03/22/2005 (10:47 am)
Yes exactly, I ran into the same problem before when trying to get the footstep triggers to work on my player character. Unfortunately I didn't track it down enough to fix it..maybe I'll look into it a bitmore today and at least pop out an error if an animation uses triggers and there is no ground transform.
#7
03/22/2005 (11:10 am)
Here's the old thread with some more info on it
#8
03/22/2005 (12:01 pm)
Ok, to add a warning for when this situation occurs
in the function:
void TSThread::transitionToSequence(S32 seq, F32 toPos, F32 duration, bool continuePlay)

right after make path is set like so: makePath = sequence->makePath();

add this little check
if(!makePath && sequence->numTriggers)
   {
	   Con::errorf("Warning: animation sequence:\"%s\" uses triggers, but does not have a ground transform exported. Triggers will not fire.",shape->getName(sequence->nameIndex));
   }


then do the exact same thing in the function void TSThread::setSequence(S32 seq, F32 toPos)

right after makePath = sequence->makePath();

if(!makePath && sequence->numTriggers)
   {
	   Con::errorf("Warning: animation sequence:\"%s\" uses triggers, but does not have a ground transform exported. Triggers will not fire.",shape->getName(sequence->nameIndex));
   }

this will give you a warning in the console with the sequence name and a reminder about how to fix it.

tested with my original problem and was warned.
#9
03/22/2005 (12:52 pm)
Thanks for the snippet Clint
#10
03/24/2005 (5:06 pm)
Very welcome hope it saves somebody a little time.
#11
01/07/2009 (4:31 pm)
HA,
i was also having trouble reading triggers in certain animations
and had tracked it down in the code to the fact that "makePath" was not set in TSThread::advancePos(), and then did a GG search for "makePath" and came upon this thread by none other than my good friend Clint Brewer!

my problems turned out to be identical, and exporting the ground animation fixed the issue.
i tried forcing the triggers to fire even without a ground animation, but the naive thing didn't immediately work, so it's just as easy to export the animations.

fwiw, to export the ground transform, our artist attached a key or two to the player bounding box.

thanks Clint!