Player AutoWalk/Run?
by Alex \"bathala\" Rufon · in Torque Game Engine · 02/26/2003 (2:38 am) · 6 replies
Hello.
I play Anarchy-Online whenever im not tinkering around with my game ... and they have this feature where you can press the Numlock 0 key and your avatar/character will continuesly run or walk (depending on its current state). You can use the mouse or the kewboard to change direction but pressing the Up/Down arrow keys will stop your character.
The question is: How do I implement this in TGE?
Thanks.
Alex
I play Anarchy-Online whenever im not tinkering around with my game ... and they have this feature where you can press the Numlock 0 key and your avatar/character will continuesly run or walk (depending on its current state). You can use the mouse or the kewboard to change direction but pressing the Up/Down arrow keys will stop your character.
The question is: How do I implement this in TGE?
Thanks.
Alex
About the author
I am an independent game developer who's never going to make it in the industry because I'm color blind and has absolutely no imagination.
#2
$mvForwardAction is the key.
Type this in the console:
Your character should begin moving forward.
Then type:
Your character stops moving forward. Basically, binding moveforward(%val) to a key does the same thing, with %val being that key state (1 = down, 0 = up). Here's my guess of what would work (I didn't test this!):
If you were slick, that would be a toggle $mvForwardAction = 1 - $mvForwardAction; (remember that the function gets called on key down and key up, so there's a little more to it than the one-liner). Testing and debugging that code is left as an exercise for the reader.
For more depth check out C:\torque\engine\game\gameConnectionMoves.cc(59): Con::addVariable("mvForwardAction", TypeF32, &mForwardAction);
. The script variable sets the member field in MoveManager, which is trasmitted from the client to the server as part of the Move object -- GameConnection does the work of setting the next Move object based on the state of MoveManager.
02/26/2003 (12:22 pm)
Check out the moveforward(%val) function in default.bind.cs in the fps mod.$mvForwardAction is the key.
Type this in the console:
$mvForwardAction=1;
Your character should begin moving forward.
Then type:
$mvForwardAction=0;
Your character stops moving forward. Basically, binding moveforward(%val) to a key does the same thing, with %val being that key state (1 = down, 0 = up). Here's my guess of what would work (I didn't test this!):
function lockforward(%val) {
$mvForwardAction=1;
}
// Pick any key that you like.
moveMap.bind( keyboard, 0, lockforward );If you were slick, that would be a toggle $mvForwardAction = 1 - $mvForwardAction; (remember that the function gets called on key down and key up, so there's a little more to it than the one-liner). Testing and debugging that code is left as an exercise for the reader.
For more depth check out C:\torque\engine\game\gameConnectionMoves.cc(59): Con::addVariable("mvForwardAction", TypeF32, &mForwardAction);
. The script variable sets the member field in MoveManager, which is trasmitted from the client to the server as part of the Move object -- GameConnection does the work of setting the next Move object based on the state of MoveManager.
#4
I apologize for not following this thread. I erroneously assumed that if I create a thread, I will be automatically notified when someone posts to it even though I didn't check the notify check box at the bottom. :D
Anyway, I'll look into this as soon as I go home (I'm still at my day job). Thanks for the suggestions. ;D
Alex
03/10/2003 (1:54 am)
Hello Guys,I apologize for not following this thread. I erroneously assumed that if I create a thread, I will be automatically notified when someone posts to it even though I didn't check the notify check box at the bottom. :D
Anyway, I'll look into this as soon as I go home (I'm still at my day job). Thanks for the suggestions. ;D
Alex
#5
This toggles auto run on or off, you could easily adjust the other movement keys to turn this off if you pressed in another direction(if you want).
-Jared
03/10/2003 (3:00 pm)
Here you go, it's pretty easyfunction autoRun(%val)
{
if(%val){
if($mvForwardAction)
$mvForwardAction = 0.0;
else
$mvForwardAction = 1.0;
}
}
moveMap.bind(keyboard, "shift y", autoRun);This toggles auto run on or off, you could easily adjust the other movement keys to turn this off if you pressed in another direction(if you want).
-Jared
#6
It works! It works! Thanks to everyone specially to Brad and Jared. :D
The following code should be in client/scripts/default.bind.cs
As you can see from the code, I had to modify the moveBackward function so that it would cancel the lockForward function. Otherwise, if you press the reverse key and release it ... your avatar will start walking forward again.
Again thanks.
Alex
03/11/2003 (6:45 pm)
Hello everybody,It works! It works! Thanks to everyone specially to Brad and Jared. :D
The following code should be in client/scripts/default.bind.cs
function movebackward(%val)
{
$mvBackwardAction = %val;
// Make sure that we dont move forward again
$mvForwardAction = 0.0;
}
function lockForward(%val)
{
if(%val){
if($mvForwardAction)
$mvForwardAction = 0.0;
else
$mvForwardAction = 1.0;
}
}
moveMap.bind(keyboard, "shift w", lockForward);As you can see from the code, I had to modify the moveBackward function so that it would cancel the lockForward function. Otherwise, if you press the reverse key and release it ... your avatar will start walking forward again.
Again thanks.
Alex
Associate Ken Finney
Tubetti World