Need Help - $mvTriggerCount and NPCs
by Nicolai Dutka · in Torque Game Engine Advanced · 06/22/2010 (11:07 am) · 24 replies
I've over-analyzed this whole thing and want to start over:
All I need is to force an AI player to 'jump' and more importantly, 'jetJump'.
I've tried:
$mvTriggerCount3++; //Only works on the main player
%obj.setImageTrigger(2,true); //Only seems to work on weapons, not on movement commands
I did a LOT of forum searches and see a LOT of other people requesting this, dating all the way back to 2004. Am I to understand that in the last 6 years, GarageGames has done nothing at all to answer the call of a TON of its users? This seems like REALLY basic stuff to me, so why is it not implemented? More importantly, what can we do to fix it?? I NEED my AI players to be able to JetJump!!!!!!!!
All I need is to force an AI player to 'jump' and more importantly, 'jetJump'.
I've tried:
$mvTriggerCount3++; //Only works on the main player
%obj.setImageTrigger(2,true); //Only seems to work on weapons, not on movement commands
I did a LOT of forum searches and see a LOT of other people requesting this, dating all the way back to 2004. Am I to understand that in the last 6 years, GarageGames has done nothing at all to answer the call of a TON of its users? This seems like REALLY basic stuff to me, so why is it not implemented? More importantly, what can we do to fix it?? I NEED my AI players to be able to JetJump!!!!!!!!
#2
%obj.jump();
Poof, %obj just jumped.
06/22/2010 (12:17 pm)
Ultimately, what I really need is a way to force control ALL movements of ALL actors. I want to be able to say:%obj.jump();
Poof, %obj just jumped.
#3
the only other way I can imagine this can be done is using an aiconnection object.
for aiplayers, you can use the normal commands, or you can create an aiconnection, and set the aiplayer as its control object. if you have an aiconnection controlling the aiplayer, you may be able to:
or something like that.
06/22/2010 (8:27 pm)
you can simply apply an impulse to simulate a jump. aiplayers will still do the 'jump' animation even if it isn't a real jump.the only other way I can imagine this can be done is using an aiconnection object.
for aiplayers, you can use the normal commands, or you can create an aiconnection, and set the aiplayer as its control object. if you have an aiconnection controlling the aiplayer, you may be able to:
%aiconnection.setTrigger(2,true)
or something like that.
#4
But otherwise, you have the source... just add a jump method to AIPlayer! And post it as a resource for everyone else who is frustrated with this oversight ;). Should be simple enough to do. Set some flag in the character, and when getMove is next called, set the move jump trigger and clear out the jump flag.
06/22/2010 (8:50 pm)
That AIConnection trick should work, but using AIConnections just so that you can have jumping seems a bit like overkill.But otherwise, you have the source... just add a jump method to AIPlayer! And post it as a resource for everyone else who is frustrated with this oversight ;). Should be simple enough to do. Set some flag in the character, and when getMove is next called, set the move jump trigger and clear out the jump flag.
#5
How would I create the %aiconnection? This seems like it would let me turn the trigger on/off for the jetJump exactly the way I need it.
Other than that, I'm still not very good with C++ so adding a jump, jetJump, or other console methods is a bit beyond me atm...
06/22/2010 (9:16 pm)
Apply impulse is already in use, but doesn't let the AI use the jetJump. Ultimately, as of right now, that's what I REALLY need...How would I create the %aiconnection? This seems like it would let me turn the trigger on/off for the jetJump exactly the way I need it.
Other than that, I'm still not very good with C++ so adding a jump, jetJump, or other console methods is a bit beyond me atm...
#6
$ai = aiConnect("coyote");
Made a copy of my main character, with same name as main character, same weapons, etc... I do have a 'coyote' datablock, so how would I make the aiConnection use that? Also, I tried:
$ai.setTrigger(2,true);
Nothing at all happened... Also tried:
$ai.setTrigger(1,true);
$ai.setTrigger(0,true);
Nothing at all...
06/22/2010 (9:34 pm)
Tried:$ai = aiConnect("coyote");
Made a copy of my main character, with same name as main character, same weapons, etc... I do have a 'coyote' datablock, so how would I make the aiConnection use that? Also, I tried:
$ai.setTrigger(2,true);
Nothing at all happened... Also tried:
$ai.setTrigger(1,true);
$ai.setTrigger(0,true);
Nothing at all...
#7
try something like this:
$controller = new aiconnection(jumper);
$controller.setcontrolobject(aijumper);
...
$controller.setTrigger(2,true);
06/22/2010 (10:13 pm)
creating the aiconnection is similar to creating a normal player and serverconnection.try something like this:
$controller = new aiconnection(jumper);
$controller.setcontrolobject(aijumper);
...
$controller.setTrigger(2,true);
#8
Tried combining it:
$ai = aiConnect("Coyote");
$controller = new aiConnection(jumper); //also tried replacing 'jumper' with 'coyote'
//Tried these 1 at a time followed by the 'setTrigger'
$controller.setcontrolobject(aijumper);
$controller.setcontrolobject(jumper);
$controller.setcontrolobject(coyote);
$controller.setcontrolobject(aicoyote);
$controller.setTrigger(2,true);
$ai.setTrigger(2,true);
Nothing from ANY of it...
Also tried:
$ai.dump();
$controller.dump();
BOTH list "setTrigger" as a valid command.
Everything I tried still show the AI character using the same character as the main player, no coyote.
06/23/2010 (10:07 am)
@Sean, tried all that and still nothing at all...Tried combining it:
$ai = aiConnect("Coyote");
$controller = new aiConnection(jumper); //also tried replacing 'jumper' with 'coyote'
//Tried these 1 at a time followed by the 'setTrigger'
$controller.setcontrolobject(aijumper);
$controller.setcontrolobject(jumper);
$controller.setcontrolobject(coyote);
$controller.setcontrolobject(aicoyote);
$controller.setTrigger(2,true);
$ai.setTrigger(2,true);
Nothing from ANY of it...
Also tried:
$ai.dump();
$controller.dump();
BOTH list "setTrigger" as a valid command.
Everything I tried still show the AI character using the same character as the main player, no coyote.
#9
spawnActor(coyote); //my own function
$ai.setControlObject(coyote0);
echo($ai.getControlObject().getName()) = coyote0
So that much is working, but:
$ai.setTrigger(0,true);
$ai.setTrigger(1,true);
$ai.setTrigger(2,true);
None of these are doing anything at all...
I also tried it on myself:
$player.setTrigger(0,true); //error! oops, wrong object
$client.setTrigger(0,true); //no error, but player didnt shoot...
06/23/2010 (10:28 am)
$ai = aiConnect(coyote0);spawnActor(coyote); //my own function
$ai.setControlObject(coyote0);
echo($ai.getControlObject().getName()) = coyote0
So that much is working, but:
$ai.setTrigger(0,true);
$ai.setTrigger(1,true);
$ai.setTrigger(2,true);
None of these are doing anything at all...
I also tried it on myself:
$player.setTrigger(0,true); //error! oops, wrong object
$client.setTrigger(0,true); //no error, but player didnt shoot...
#10
What I'm trying to do, is create a levitation function that's usable by player and aiplayer classes. Currently, we have a "gun" that has to be equipped, then the player holds down the gun's trigger to activate it. Once released, the levitate stops. The whole thing runs on a modified 'jetJump' using $mvTriggerCount3. We added another trigger to the source code...
I can get AI to 'fire' the levitation gun and all the code for it runs fine, but the "magic" requires: $mvTriggerCount3++ and $mvTriggerCount--
Those variables are effected by $mvTriggerCount2. So, you're firing a weapon with trigger 2 which activates trigger 3. When trigger 2 is released, it deactivates trigger 3.
As you can imagine, that only effects the main player. Worse, if an enemy is told to fire the levitate weapon, it increments the main player's trigger 3. Since main player didn't activate that with THEIR 'trigger 1', it causes the main player to twitch until I manually reset their trigger.
So... maybe I need to re-think/re-write the levitation ability so it doesn't require the jet pack at all?
I was thinking maybe using a flying vehicle, or maybe just a function that will constantly set your Z position until levitate is deactivated?
I'd be happy to share ALL the code if that would help...
06/23/2010 (10:41 am)
I'm wondering if maybe I should scrap my code and start over....What I'm trying to do, is create a levitation function that's usable by player and aiplayer classes. Currently, we have a "gun" that has to be equipped, then the player holds down the gun's trigger to activate it. Once released, the levitate stops. The whole thing runs on a modified 'jetJump' using $mvTriggerCount3. We added another trigger to the source code...
I can get AI to 'fire' the levitation gun and all the code for it runs fine, but the "magic" requires: $mvTriggerCount3++ and $mvTriggerCount--
Those variables are effected by $mvTriggerCount2. So, you're firing a weapon with trigger 2 which activates trigger 3. When trigger 2 is released, it deactivates trigger 3.
As you can imagine, that only effects the main player. Worse, if an enemy is told to fire the levitate weapon, it increments the main player's trigger 3. Since main player didn't activate that with THEIR 'trigger 1', it causes the main player to twitch until I manually reset their trigger.
So... maybe I need to re-think/re-write the levitation ability so it doesn't require the jet pack at all?
I was thinking maybe using a flying vehicle, or maybe just a function that will constantly set your Z position until levitate is deactivated?
I'd be happy to share ALL the code if that would help...
#11
This activates levitate:
Here's all the levitate related functions. Note lines 25-26 and 38-39
06/23/2010 (10:44 am)
Screw it, here's all my code:This activates levitate:
function Armor::onTrigger(%this, %obj, %triggerNum, %val)
{
// This method is invoked when the player receives a trigger move event.
// The player automatically triggers slot 0 and slot one off of triggers # 0 & 1.
// Trigger # 2 is also used as the jump key.
if(%triggerNum == 1) // Check for spell trigger (trigger1)
{
// Check for the specific spellgun equipped
// If appropriate weapon, pass on information about the trigger event
// Levitate
if(%obj.isImageMounted(SpellGun_LevitateImage) && (%obj.getEnergyLevel() >= 1))
{
levitationTrigger(%obj,%val);
manageEnergy(%obj); //Tracks energy usage
}
}
if(%triggerNum == 2) // Check to see if they try to jump
{
if((($mvTriggerCount3 % 2) == 1) && %obj.isImageMounted(SpellGun_LevitateImage))
%obj.setVelocity("0 0 0"); // Make it so if they try to jump while levitating, they just... stop.
}
}Here's all the levitate related functions. Note lines 25-26 and 38-39
//--------------------------------------------------------------------
function doLevitation(%obj)
{
if(%obj.canLevitate)
{
processMastery("Levitate",%obj);
%obj.levitating = true;
manageLevitation(%obj); // Make sure player can't levitate too high (scale walls)
if(%obj.getEnergyLevel() >= 2)
{
%obj.setActionThread("levitate");
if(%obj.isFalling == false)
{
%transform = %obj.getTransform();
%xPos = getWord(%transform, 0);
%yPos = getWord(%transform, 1);
%zPos = getWord(%transform, 2) + 1;
%rots = getWord(%transform, 3) SPC getWord(%transform, 4) SPC getWord(%transform, 5) SPC getWord(%transform, 6);
%newTransform = %xPos SPC %yPos SPC %zPos SPC %rots;
%obj.setTransform(%newTransform);
}
//if(!($mvTriggerCount1 % 2 ? 1 : 0))
// return;
if(%obj.getEnergyLevel() >= 1 && ($mvTriggerCount3 % 2) == 0)
$mvTriggerCount3++;
else
return;
}
}
}
function stopLevitation(%obj)
{
SFXStop(%obj.levitateSound);
setCanLevitate(%obj,false);
%obj.levitateStartZ = 0;
if($mvTriggerCount3 % 2 == 1)
$mvTriggerCount3--;
if(%obj.levitating)
%obj.levitating = !%obj.levitating;
%obj.setActionThread("base");
schedule(750,0,setCanLevitate,%obj,true);
}
function levitationTrigger(%obj,%val)
{
echo("Levitation Trigger: %val: "@%val);
if(%val) {
%obj.levitateStartZ = getWord(%obj.getTransform(),2);
if(%obj.levitateSound) SFXStop(%obj.levitateSound);
%obj.levitateSound = SFXPlay(SpellGun_LevitateFireSound,getWord(%obj.getPosition(),0),getWord(%obj.getPosition(),1),getWord(%obj.getPosition(),2));
%obj.setVelocity("0 0 0");
doLevitation(%obj);
}
else
stopLevitation(%obj);
}
function manageLevitation(%obj)
{
%z = getWord(%obj.getTransform(),2) - 2;
if( %z > %obj.levitateStartZ )
{
error("Levitate too high!");
stopLevitation(%obj);
}
if(%obj.levitating) schedule(50,0,manageLevitation,%obj);
}
function setCanLevitate(%obj,%bool)
{
%obj.canLevitate = %bool;
}
#12
Maybe you need to set the jumpforce in your ai's datablock? also, make sure your NPC's are using the Armor class, by setting classname = "Armor" in the NPC's datablock.
Also, are you sure setTrigger isn't doing anything? setTrigger() will only do something if the ai character is armed with a weapon. Are you able to get your NPC's to shoot using the normal commands?
06/23/2010 (7:36 pm)
Nicolai-Maybe you need to set the jumpforce in your ai's datablock? also, make sure your NPC's are using the Armor class, by setting classname = "Armor" in the NPC's datablock.
Also, are you sure setTrigger isn't doing anything? setTrigger() will only do something if the ai character is armed with a weapon. Are you able to get your NPC's to shoot using the normal commands?
#13
%obj.setImageTrigger(%slot,%bool);
However, look at that 2nd chunk of code at lines 25-26 and 38-39. The levitate 'gun' is only effecting the main player because of those lines.
EDIT:
Oh ya, I can verify the NPCs are in fact 'firing' the levitate gun using a simple echo statement within the 'doLevitate' function.
06/23/2010 (7:45 pm)
NPC's are 'firing' all the weapons using:%obj.setImageTrigger(%slot,%bool);
However, look at that 2nd chunk of code at lines 25-26 and 38-39. The levitate 'gun' is only effecting the main player because of those lines.
EDIT:
Oh ya, I can verify the NPCs are in fact 'firing' the levitate gun using a simple echo statement within the 'doLevitate' function.
#14
%obj.setImageTrigger() should work but it doesn't. are you as surprised as I am?
I took a look in the source and I see why it's not working. It just wasn't intended to work.
however, I have an idea that might work without changing any source code. try setting an invisible mounted image in slot 3 before calling setImageTrigger().
it's hacky, but it may work. =)
06/23/2010 (9:59 pm)
the $mvTriggerCount are only applicable to the main control object.%obj.setImageTrigger() should work but it doesn't. are you as surprised as I am?
I took a look in the source and I see why it's not working. It just wasn't intended to work.
however, I have an idea that might work without changing any source code. try setting an invisible mounted image in slot 3 before calling setImageTrigger().
it's hacky, but it may work. =)
#15
And yes, %obj.setImageTrigger(%slot,%bool) DOES work and always has been....
06/24/2010 (8:33 am)
The NPC already has a weapon image. It doesn't matter WHO fires the weapon, the 'doLevitation' is being called whenever that gun is fired by ANYONE. Again, look at lines 26 and 39 in my second chunk of code above. No matter who fires the weapon, those lines will ALWAYS ONLY effect the main player.And yes, %obj.setImageTrigger(%slot,%bool) DOES work and always has been....
#16
It's a direct input command ... so will only affect the player (or other user control object).
If "$mvTriggerCount3" is jump and you want an AI to jump, then you'd have to write a code function for AiPlayer::jump (cos I don't think there is a stock function for this) or apply a vertical impulse to the bottom of the AiPlayer which would simulate a hacky jump.
06/24/2010 (9:28 am)
As Sean pointed out Quote:$mvTriggerCount are only applicable to the main control object
It's a direct input command ... so will only affect the player (or other user control object).
If "$mvTriggerCount3" is jump and you want an AI to jump, then you'd have to write a code function for AiPlayer::jump (cos I don't think there is a stock function for this) or apply a vertical impulse to the bottom of the AiPlayer which would simulate a hacky jump.
#17
The trigger is not a jump, but a 'jetJump'. Big difference!! Jet Jump uses energy and can be "held down" to sustain the lift. I haven't the slightest idea how to 'hack' that into anything even remotely feasible...
06/24/2010 (9:31 am)
Exactly my point Steve! I've been saying this the whole time!!!!!The trigger is not a jump, but a 'jetJump'. Big difference!! Jet Jump uses energy and can be "held down" to sustain the lift. I haven't the slightest idea how to 'hack' that into anything even remotely feasible...
#18
it sounds like you are looking for something very particular for your game. I dont think torque supports the functionality you need. if you're not going to make any c++ changes, I would suggest either finding some way to do it using applyimpulse(), or just drop the feature from your game.
you could also try setting a bounty and pay a contractor to implement the feature you want.
06/24/2010 (7:48 pm)
I wasn't sure what you meant by jetJump. I never heard of that before.it sounds like you are looking for something very particular for your game. I dont think torque supports the functionality you need. if you're not going to make any c++ changes, I would suggest either finding some way to do it using applyimpulse(), or just drop the feature from your game.
you could also try setting a bounty and pay a contractor to implement the feature you want.
#19
jetJump is stock code in TGEA and T3D. We have the levitate working already for the player, so I refuse to believe it can't be altered to work on AIPlayers as well. I do appreciate the help you've given, but it sounds like you need to do your research... I realize you don't have TGEA, but TGEA comes with a "T3D" game example in which, right-click makes you 'jetJump'. I know for fact T3D has the same code because I'm using it right now! :D
In TGEA stock folders:
C:\Torque\TGEA_1_8_1\GameExamples\T3D\T3D.exe
Run the game and as soon as you get in, simply right-click. You fly straight up in the air. The longer you hold, the higher you go (until you run out of energy).
We simply modified the code to restrict your height and reduced the fall speed dramatically. Voila, instant levitate. Now if only we could get AI to use it, we'd be golden!
06/24/2010 (9:13 pm)
@ seanjetJump is stock code in TGEA and T3D. We have the levitate working already for the player, so I refuse to believe it can't be altered to work on AIPlayers as well. I do appreciate the help you've given, but it sounds like you need to do your research... I realize you don't have TGEA, but TGEA comes with a "T3D" game example in which, right-click makes you 'jetJump'. I know for fact T3D has the same code because I'm using it right now! :D
In TGEA stock folders:
C:\Torque\TGEA_1_8_1\GameExamples\T3D\T3D.exe
Run the game and as soon as you get in, simply right-click. You fly straight up in the air. The longer you hold, the higher you go (until you run out of energy).
We simply modified the code to restrict your height and reduced the fall speed dramatically. Voila, instant levitate. Now if only we could get AI to use it, we'd be golden!
#20
From T3D:
art/datablocks/player.cs
06/24/2010 (9:24 pm)
A little proof for my pudding:From T3D:
art/datablocks/player.cs
airControl = 0.3; jetJumpForce = 6 * 10; jetJumpEnergyDrain = 0.5; jetMinJumpEnergy = 1;
Torque 3D Owner Nicolai Dutka