Forum

Help with self.velocity

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Help with self.velocity

Postby redrum » Wed Sep 12, 2007 11:00 pm

Guys, I'm trying to get the player to slow down as he picks up nails and rockets. I added this code to PlayerPostThink:

Code: Select all
 self.velocity_x = self.velocity_x * (1 - ( (self.ammo_nails * .0001) + (self.ammo_rockets * .001) ) );
 self.velocity_y = self.velocity_y * (1 - ( (self.ammo_nails * .0001) + (self.ammo_rockets * .001) ) );


It works pretty good :o , except for when I jump.

It seems that the velocity in the air is affected much more than the velocity while on the ground.

self.velocity_z seems to be just fine. x and y seem to slow down 2-3 times as much while airborne. I can't figure this one out. Any help?
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Dr. Shadowborg » Thu Sep 13, 2007 1:37 am

This would be because when you're in the air, your velocity for keypress is greatly reduced. (Meaning when you're on the ground you can move fast enough when holding down a direction key to offset your reduction code. However, when you're in the air, this is cut almost to zero.)

You'll have to figure out a way of just simply limiting it so that it doesn't exceed a certain figure. i.e. figure out the player's maximum normal velocity, then apply your weight stuff, and finally lock the x and y self.velocity to not exceed the x and y of your limiting figure.
User avatar
Dr. Shadowborg
InsideQC Staff
 
Posts: 1110
Joined: Sat Oct 16, 2004 3:34 pm

Postby FrikaC » Thu Sep 13, 2007 2:54 am

This code isn't happening every frame is it (e.g. in PlayerPreThink or PlayerPostThink or one of the functions they call?). Because if so, it's also framerate dependant. If you have a slower computer, you will move faster (fewer reductions per second), a faster computer and you will move slower (more reductions per second).

I suggest doing what Dr. Shadowb0rg recommended in his last reply.
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby redrum » Fri Sep 14, 2007 2:28 pm

What do these lines of code mean?

Code: Select all
if (!(self.flags & FL_ONGROUND))


Code: Select all
if ( !(self.flags & FL_JUMPRELEASED) )
Welcome to the Overlook Hotel: The-Overlook-Hotel.game-server.cc
User avatar
redrum
 
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Postby Dr. Shadowborg » Fri Sep 14, 2007 3:56 pm

redrum wrote:What do these lines of code mean?

Code: Select all
if (!(self.flags & FL_ONGROUND))


Code: Select all
if ( !(self.flags & FL_JUMPRELEASED) )


The first means: if I'm NOT on the ground.
The second means: if I haven't released the jump key

Remember that the ! is an operator for NOT.
User avatar
Dr. Shadowborg
InsideQC Staff
 
Posts: 1110
Joined: Sat Oct 16, 2004 3:34 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest