Help with self.velocity

Discuss programming in the QuakeC language.
Post Reply
redrum
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Help with self.velocity

Post by redrum »

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
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Post by Dr. Shadowborg »

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.
FrikaC
Site Admin
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Post by FrikaC »

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.
redrum
Posts: 410
Joined: Wed Mar 28, 2007 11:35 pm
Location: Long Island, New York

Post by redrum »

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
Dr. Shadowborg
InsideQC Staff
Posts: 1120
Joined: Sat Oct 16, 2004 3:34 pm

Post by Dr. Shadowborg »

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.
Post Reply