Forum

getting up from crouching

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

getting up from crouching

Postby Boss429 » Mon Dec 04, 2006 6:26 am

I followed this tutorial: http://www.inside3d.com/showtutorial.php?id=169
I am trying to fix the bug where you don't stand up automatically after getting out of a tunnel.
I put :
Code: Select all
if (self.crouch && !self.impulse == 33)
   {
       crouch_off ();
    }

at the end of CheckPowerups in client.qc.
now when I hit crouch it hops up a little, like a jump or something.
Why does this happen?
My thinking was: IF crouch is on AND the button isn't held down AND you aren't in a tunnel THEN turn crouch off.
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Re: getting up from crouching

Postby DieparBaby » Tue Dec 05, 2006 5:48 pm

Boss429 wrote:I followed this tutorial: http://www.inside3d.com/showtutorial.php?id=169
I am trying to fix the bug where you don't stand up automatically after getting out of a tunnel.
I put :
Code: Select all
if (self.crouch && !self.impulse == 33)
   {
       crouch_off ();
    }

at the end of CheckPowerups in client.qc.
now when I hit crouch it hops up a little, like a jump or something.
Why does this happen?
My thinking was: IF crouch is on AND the button isn't held down AND you aren't in a tunnel THEN turn crouch off.


Couple problems here, I think. First "!self.impulse == 33" will never be true. It should
be "self.impulse != 33". This is because !self.impulse will be 1 if self.impulse is 0 and !self.impulse will be 0 if self.impulse is any other value.

Second, self.impulse will always be 0 in CheckPowerups because it is set to zero at the end of ImpulseCommands in weapons.qc. So unless an impulse calls a function that calls CheckPowerups, self.impulse will always be 0.
User avatar
DieparBaby
 
Posts: 44
Joined: Tue Dec 05, 2006 3:27 pm
Location: London, Ontario, Canada, eh

Re: getting up from crouching

Postby Boss429 » Tue Dec 05, 2006 6:34 pm

DieparBaby wrote:
Boss429 wrote:I followed this tutorial: http://www.inside3d.com/showtutorial.php?id=169
I am trying to fix the bug where you don't stand up automatically after getting out of a tunnel.
I put :
Code: Select all
if (self.crouch && !self.impulse == 33)
   {
       crouch_off ();
    }

at the end of CheckPowerups in client.qc.
now when I hit crouch it hops up a little, like a jump or something.
Why does this happen?
My thinking was: IF crouch is on AND the button isn't held down AND you aren't in a tunnel THEN turn crouch off.


Couple problems here, I think. First "!self.impulse == 33" will never be true. It should
be "self.impulse != 33". This is because !self.impulse will be 1 if self.impulse is 0 and !self.impulse will be 0 if self.impulse is any other value.

Second, self.impulse will always be 0 in CheckPowerups because it is set to zero at the end of ImpulseCommands in weapons.qc. So unless an impulse calls a function that calls CheckPowerups, self.impulse will always be 0.

ah ok, thanks. How should I check to make sure the crouch button is held down?
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby DieparBaby » Tue Dec 05, 2006 8:22 pm

As far as I know, when you bind a key to an impulse, holding the key down is no different then simply tap the key once. For example, if you set up your mod so that the fire command was done through an impulse and you held down the key that was bound to the impulse, your weapon would only fire once. To fire again, you would have to release the key and hit it again.

According to the crouch tutorial, one impulse (key) makes you crouch and stay crouched and another impulse (key) makes you stand up. If you want to check if you are crouched you have to check the .crouch variable. If its 1 you are crouching, otherwise you aren't.
User avatar
DieparBaby
 
Posts: 44
Joined: Tue Dec 05, 2006 3:27 pm
Location: London, Ontario, Canada, eh

Postby CocoT » Tue Dec 05, 2006 8:33 pm

Maybe this is going to sound super-silly and, be warned, I'm known in the mod community for my weird fixes and hacks... Maybe you could create an invisible entity at the end and start of tunnels which, once touched, would check if the player is crouching/standing or not and do the impulse for him/her? You know, at the end of whatever tunnel, if the player touches that entity and is close enough to the end to stand up, then that the touch function of that entity would send a signal for the player's impulse to be called?
I'm sure there are better ways to do this, though :P
User avatar
CocoT
 
Posts: 695
Joined: Tue Dec 14, 2004 5:39 pm
Location: Belly-Gum

Postby DieparBaby » Tue Dec 05, 2006 8:36 pm

If you want to fix this bug, put a check in the code that makes you stand up that does a traceline to see if there is enough space to stand up. I think the player height is 56.
User avatar
DieparBaby
 
Posts: 44
Joined: Tue Dec 05, 2006 3:27 pm
Location: London, Ontario, Canada, eh

Postby RenegadeC » Tue Dec 05, 2006 8:49 pm

DieparBaby wrote:If you want to fix this bug, put a check in the code that makes you stand up that does a traceline to see if there is enough space to stand up. I think the player height is 56.


You'll need more than a single traceline as you're only checking the center of the player (or wherever else you're tracelining from the player), you're going to have to check every possible angle along the players bounding box otherwise you're going to get stuck in geometry.

It's best to spawn an invisible entity that's the player size that checks if it's able to move (using walkmove(0,0)) before allowing the player to stand up.

So in possible order of coding:
1. Spawn an invisible entity
2. Invisible entity is players size, and probably above the player to check if it's okay to stand
3. Invisible entity runs a walkmove(0,0) which is stored in a variable that gets sent to the player entity
4. If the variable is true, then you can stand, otherwise no.

I really don't get why this method isn't used more often, I've used it for a few tricks in TAoV such as grabbing monsters and grabbing ledges. The only bad aspect is spawning entities sends a lot of network traffic, but so does the nailgun.
User avatar
RenegadeC
 
Posts: 391
Joined: Fri Oct 15, 2004 10:19 pm
Location: The freezing hell; Canada

Postby Sajt » Tue Dec 05, 2006 9:12 pm

Invisible entities don't get sent over the network :O
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby DieparBaby » Tue Dec 05, 2006 9:26 pm

Renegade:

ah. That was kinda simplistic of me.
User avatar
DieparBaby
 
Posts: 44
Joined: Tue Dec 05, 2006 3:27 pm
Location: London, Ontario, Canada, eh

Postby Boss429 » Wed Dec 06, 2006 1:02 am

Well I'd don't really like the thought of placing entities at the end of every tunnel :?
And even if I did I still need to check if the crouch button is held down right? Because what if I'm going through a tunnel and when I get to the other side I keep holding down crouch, wouldn't I get up anyways?
So it sounds like there is no way to check if the crouch button is held down because it's an impulse right? So I'd need to make it like the weapon fire key. Could I make say a "button3" (in Defs.qc) without modifying the engine? I'm using DarkPlaces.
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby Sajt » Wed Dec 06, 2006 2:06 am

The way you do this without a +button3 is:

Console/CFG:
alias +crouch "impulse 50"
alias -crouch "impulse 51"

then in the code, impulse 50 calls the crouching code (e.g. setting a 'crouching' flag), impulse 51 calls the uncrouching code (e.g. removing the 'crouching' flag).

DarkPlaces lets you use +button3, yes. If you look at DPMod, it comes with a file called dpextensions.qc. Just grab this and add it to your progs.src after defs.qc. It includes all the QC declarations required to use DarkPlaces's extra QC features. It includes .button3 (all the way through .button3). So you can check the player's button3 field instead of creating a new one and controlling it with impulses.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby scar3crow » Wed Dec 06, 2006 2:36 am

Is this for Transfusion? I would assume so since its involving crouching, and Darkplaces - if that is the case, an engine amendment would be acceptable since you guys use your own rate on using the binary...

The trigger brush for correcting it would cause problems, aside from complicating map making, because you would have to more than likely have it disable crouching for a few seconds upon touch, otherwise if you held it down you could have a dominance fight between the brush and the player command.

I think RenegadeC got it with sending a test entity using walkmove to see if there is enough valid space - similar to if you would want to check if an area is large enough for a remote teleporter before allowing the player to go on through.
User avatar
scar3crow
InsideQC Staff
 
Posts: 1054
Joined: Tue Jan 18, 2005 8:54 pm
Location: Alabama

Postby Sajt » Wed Dec 06, 2006 6:10 am

CocoT's idea is completely unnecessary. RenegadeC got it right. Don't listen to CocoT!

Sorry CocoT, here have some boobies.

Image
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby Boss429 » Wed Dec 06, 2006 6:38 am

Sajt wrote:The way you do this without a +button3 is:

Console/CFG:
alias +crouch "impulse 50"
alias -crouch "impulse 51"

then in the code, impulse 50 calls the crouching code (e.g. setting a 'crouching' flag), impulse 51 calls the uncrouching code (e.g. removing the 'crouching' flag).

DarkPlaces lets you use +button3, yes. If you look at DPMod, it comes with a file called dpextensions.qc. Just grab this and add it to your progs.src after defs.qc. It includes all the QC declarations required to use DarkPlaces's extra QC features. It includes .button3 (all the way through .button3). So you can check the player's button3 field instead of creating a new one and controlling it with impulses.

Ok good, I'll try to adapt the code to use button3 instead of an impulse.
scar3crow wrote:Is this for Transfusion? I would assume so since its involving crouching, and Darkplaces - if that is the case, an engine amendment would be acceptable since you guys use your own rate on using the binary...

No this isn't for Transfusion, Willis (I'm guessing it was him) already has it coded and it will be available with the next version of Transfusion. I'm just messing around and trying to learn a thing or two about QuakeC. Thanks for the info guys.
Boss429
 
Posts: 39
Joined: Sun Dec 03, 2006 7:29 pm

Postby CocoT » Wed Dec 06, 2006 8:21 am

Oh n0, noOoOoOOOOooOOooOO!

/me 's eyes burn, inflicting CocoT atrocious pain

Note: Hey, at least I got the word "invisible" right! :P
But yeah, erm, when it comes to coding tips, it's probably a good idea not to listen to me :(
User avatar
CocoT
 
Posts: 695
Joined: Tue Dec 14, 2004 5:39 pm
Location: Belly-Gum

Next

Return to QuakeC Programming

Who is online

Users browsing this forum: Bing [Bot] and 1 guest