Game Development Community

Key combos

by Joel Hargarten · in Technical Issues · 07/07/2005 (9:48 am) · 9 replies

Hey,
here is what I WANT to do:
I have created several different jump animations based on direction. I want to have something where you are going forward and jump its a front-flip, backwards and jump its a back-flip, and so on.

How would I do this? I've tried binding the keys to different animations, but I want just one jump button, "space", and the jumps to be decided based on what direction your moving. Any help would be great, thanks.

#1
07/07/2005 (11:13 am)
Make a global variable that holds the direction your character is moving. Update the variable in your movement functions. Then, in your jump function play an animation based on the value of the global variable.

For example:
$moveDir = "none";

function MoveForward(%val) {
   if (%val) $moveDir = "forward";
   else if ($moveDir $= "forward") $moveDir = "none";
}

function Jump(%val) {
   if (%val) {
      switch$ $moveDir {
      case "forward":
         JumpForward();
      case "backward";
         JumpBackward();
      // etc...
      }
   }
}

I probably made some syntax mistakes and that is obviously not all of the code, but you get the picture.

And, in the future you should probably post something like this in the Torque public forums.
#2
07/07/2005 (12:11 pm)
Thanks a lot, thats a good start. I need to ask someone where the jump animtion is actually played. I've been trying to follow the path, but I've reached some trouble.

In 'default.bind.cs' there is the code, movemap.bind(keyboard, space, jump). that binds the space to key call the 'jump' funtion when pressed. but the 'jump' function just increments $mvtriggerCount2. I assume that this tells another function that space has been pressed and then plays the animation, but where does it do that?
#3
07/07/2005 (12:27 pm)
The $mvtriggercount2 is bound to the jump function by default. just like $mvtriggercount0 automatically triggers the shapebaseimage in slot 0 and $mvtriggercount1 automatically triggers the shapebaseimage in slot 1. there is no script which defines this functionality, its built into the source. this is one of the limitations of the scripting language. you can override the functionality of any $mvtriggercountn but, by default, $mvtriggercount2 will only run the exported "jump" animation. if you want different kinds of jumps youll have to make them custom animations and playthread().
#4
07/07/2005 (2:37 pm)
Ok, That explains a lot of things for me.
Now, I've been trying to use playthread() to play my animations, but its not working. Let me give you the setup:

I added my animation at sequence 36 in 'data/shapes/player/player.cs' and called it backflip. now I then went into 'default.bind.cs' and went to the 'jump' function. I then put the command %obj.playThread(0,"backflip"); needless to say it didnt work. I assume because there is no '%obj' in that script, but thats just my first guess. What code am I missing & where do I need to put it. Thanks.
#5
07/07/2005 (4:25 pm)
Ok, That explains a lot of things for me.
Now, I've been trying to use playthread() to play my animations, but its not working. Let me give you the setup:

I added my animation at sequence 36 in 'data/shapes/player/player.cs' and called it backflip. now I then went into 'default.bind.cs' and went to the 'jump' function. I then put the command %obj.playThread(0,"backflip"); needless to say it didnt work. I assume because there is no '%obj' in that script, but thats just my first guess. What code am I missing & where do I need to put it. Thanks.
#6
07/07/2005 (4:33 pm)
Creating and adding a custom animation is a big topic, first look at this
http://www.garagegames.com/mg/forums/result.thread.php?qt=18882
and this
http://www.garagegames.com/mg/forums/result.forum.php?qf=17
:)
#7
07/08/2005 (10:03 am)
I've been looking through the player.cc & player.h. The game already chooses between two jumps, either the standJumpAnim or the JumpAnim. when running forward and jumping it uses the JumpAnim, but when your not running, it uses the standJumpAnim. I want another jump to work the same way, but to use a backfilpAnim when running backwards and jumping. I'm not sure how the game chooses between the two but I found this function around line 409 in player.cc:

bool PlayerData::isJumpAction(U32 action)
{
   return (action == JumpAnim || action == StandJumpAnim);
}
There are also a few other things in player.cc that have to do with this. Now I've tried to add in another jump, for a backflip, next to these, but I've run into some problems. So I'll throw out this question:
How do I use the system in player.cc, that chooses which jump to use, to add another one to it?
#8
07/11/2005 (7:25 pm)
Can someone who understands c++ translate this code for me with full detail?

setActionThread((mVelocity.len() < 0.5) ? PlayerData::StandJumpAnim: PlayerData::JumpAnim, true, false, true);
#9
07/13/2005 (12:00 am)
I've only had Torque for about a week, but I know C.

This is a function call, with some confusing stuff in the middle:

setActionThread( ???????????, true, false, true);

the first parameter of that function call is some obscure C syntax:

(mVelocity.len() < 0.5) ? PlayerData::StandJumpAnim : PlayerData::JumpAnim

broken down into its parts:

aaa ? bbb : ccc
where:
aaa := (mVelocity.len() < 0.5)
bbb := PlayerData::StandJumpAnim
ccc := PlayerData::JumpAnim

the construct aaa ? bbb : ccc is a very simple if-then kinda thing. The expression aaa is evaluated. (So if evaluating aaa changes any variables, keep those changes in mind when evaluating the rest of the expression.) If the result from evaluating aaa is 'true', then expression bbb is evaluated and its value is returned. If the result from evaluating aaa is 'false' instead, then expression ccc is evaluated and its value is returned instead.

So the system does this:
call function mVelocity.len()
compare that return value with 0.5. Is it less than 0.5? Then the system uses PlayerData::StandJumpAnim. Is it greater than or equal to 0.5? Then the system uses PlayerData::JumpAnim.
Whatever result it finds, it calls function setActionThread() with that result as the first argument, and the next three arguments as true, false, true.

If those function calls were to modify things, you would need to know that mVelocity.len() is called first, and the result of any environment or memory contents changes are fed into the eventual call to setActionThread(). len() probably doesn't modify anything though, so you may not need to worry about that.

Sorry if there was any confusing stuff in there. (You know, I wonder what would happen if CS programs started teaching people about C using BNF grammars and parse trees first. There'd be more dropouts, but would people learn to write better code? Maybe asking this question means I should never teach. :-) )