Game Development Community

Adding a crouch to players for FPS

by Ian Morrison · in Torque Game Engine · 03/14/2006 (6:11 pm) · 17 replies

A crouch is something thats fairly vital to my game design. Moving while crouching isn't a high priority, but the ability to bring your profile down to cover yourself is.

I've done a search around the site. The "adding new positions" resource looks interesting, and I'll probably implement some of the stuff in that tutorial. However, it doesn't answer all my questions.

First off, I want to bind crouch to the ctrl key. I'm not sure if it was simply a matter of not doing it right, but when I tried to bind something to ctrl before it didn't work. I also want the crouch to begin when the button is pressed and finished when released.

In addition, I want to delay the "land" animation (that I'm using as a placeholder) so that the player animation stays down until the ctrl key is released. How can I do that?

#1
03/14/2006 (6:12 pm)
Are you using Max, Maya, Lightwave, Milkshape, Blender, etc? You will need to set up the animation there first.
#2
03/14/2006 (6:23 pm)
moveMap.bindCmd(keyboard, "ctrl w", "commandToServer(\'playCel\',\"wave\");", "");

That is for binding a command to the ctrl + another key. In this case ctrl+w. All it does, is link to 'commandToServer' which links to this function in code:

function serverCmdPlayCel(%client,%anim)
{
   if (isObject(%client.player))
      %client.player.playCelAnimation(%anim);
}

All you would have to do, is create a animation within Max, Maya, Lightwave, etc. then call the animation through that function.
#3
03/14/2006 (6:28 pm)
I'm not sure if that would change the bounding box though...
#4
03/14/2006 (6:35 pm)
It wouldn't. There was a resource that would swap bounding boxes a long time ago, but I don't know if it has been updated or if it is even still around (I'm sure it is, but I haven't seen it in quite a long time). It addressed this specific issue, I believe.
#5
03/14/2006 (6:46 pm)
Searching is fun!

Edit: The "Adding new positions and moves..." resource works with a tiny bit of bug fixing. My only real gripe with it is the swimming, but then again, swimming is a pretty game specific thing.
#6
03/14/2006 (6:48 pm)
(un)interestingly enough, the first link was the one that I was thinking of...and the one he mentioned...
#7
03/14/2006 (8:40 pm)
I've looked at the changing positions resource before, as I stated in my post. It'll probably be something I'll reference. I know how most people in forums like these dislike it when someone comes asking for help without trying to help themselves first, so I try to make use of the search function before I come in and make an ass of myself.

My questions were more in regards to the control functionality (crouching only when ctrl is held) and the animation.

I CANNOT make myself new animations for the crouch, due to both not being a competent 3D modeller/animator (I'm a programmer and 2D artist only) and not having that much time to devote to my torque project at this moment (I have another, more important game project in the works... I'm the lead programmer there, and since they need me to work in order for much to be done, it takes priority). Because of this, I need to use placeholder animations that APPROXIMATE what I want. The best I can find in the default torque animations is the "land" animation. If I could delay that animation until the ctrl key was let up, it would do the job perfectly.
#8
03/14/2006 (8:49 pm)
Have your animator make box animations specific to the needs. It will be much better in the long-run than trying to adapt two systems to something that was never meant to do what you want and that you'll ahve to rewrite anyway.
#9
03/15/2006 (11:37 am)
Again, I don't have the option of a custom made animation. I'm working alone here and have neither the tools nor the expertise to get it working. I'd be quite satisfied with a hack that delayed the fall animation while crouched. I've seen the animation delayed when you fall from a huge height, so I think its possible.

Whether or not its a bad plan in the long run is irrelevant, because all I'm trying to do is create the *gameplay*.
#10
03/15/2006 (12:09 pm)
The positions resource also has a download for crouch, prone, and swimming animation that work with Torque Ork.
#11
03/15/2006 (3:09 pm)
@ Ian Morrison

Forgive me if I'm wrong but this is how I interpret your post.

You want crouching functionality, you know of the resource everyone keeps going on about but that's not what you're asking about. You're asking about creatin a toggle function so you crouch whilst it is held down and rise to a stand once it's released.

If this is the case you can use something like this in your bind for the crouch function...
function changePlayerPosition(%val)
{
   //1=stand, 2=crouch, 3=prone

   if (%val == 1) { //Key down
      CommandtoServer('SetPlayerPos', 2);
   }

   else if (%val == 0) { //Key up
      CommandtoServer('SetPlayerPos', 1);
   }
}
#12
03/15/2006 (4:11 pm)
@ Tim

So if I bind a button to that, it'll call it both on press and release? Sweet, didn't know it worked that way. Thanks!

I've had problems binding things to ctrl, though. It could very well just be me goofing up, but is there a problem in torque with binding something to ctrl alone (because it's used in combinations)?

@ Dave

Thanks for mentioning that. While it wasn't included in the resource itself, your post prompted me to sift through the comments. Someone posted animations for the orc fairly far down the list. I'll post the links here for the benefit of the search function.

http://jovechiere.no-ip.com/wc/temp/swimming+crouch.rar
http://jovechiere.no-ip.com/wc/temp/prone.rar

Nice of the guy to make them available like that.

(directly pasting those into a browser doesn't work, you have to go to http://jovechiere.no-ip.com/wc/temp/ and then select the file you want)
#13
03/15/2006 (5:30 pm)
There's no problem using control alone to bind a function, you just have to specify which one. IE right or left control...

//for left control
moveMap.bind(keyboard, "lcontrol", changePlayerPosition);

//for right control
moveMap.bind(keyboard, "rcontrol", changePlayerPosition);
#14
03/15/2006 (7:45 pm)
Ah, thanks. So thats what I was doing wrong...
#15
03/15/2006 (9:17 pm)
Thanks for the help guys, I've got a working crouch implemented now. Next on the list, lowering the view when crouching. A search didn't turn anything up, but I plan to take a look through player.h tomorrow and see what I can find.
#16
03/16/2006 (8:26 am)
That would be part of the animation. though if you did want to do it in code look in player.cc and change the geteyetransform so that it returns the position minus 5 on the z.
#17
03/18/2006 (1:52 pm)
Thanks, thats what I needed!