SV_Friction/trigger push and Turning

Discuss programming in the QuakeC language.
Post Reply
Alex
Posts: 24
Joined: Sun Feb 13, 2011 6:24 pm

SV_Friction/trigger push and Turning

Post by Alex »

Hey guys,
This is probably the first of many questions for this mod, but here goes...

I'm making a mod using Darkplaces that is essentially a biking game. I'm using a bit of hardware to interface with a real bicycle mounted on a stationary trainer, which then feeds into the mod. Biking faster on the real bike means you race faster in the game, turning the handlebars turns the view etc.

I'm trying to get the feel of biking just right and I have two questions.

1. Is there a way to manipulate SV_Friction for a forward movement only?
I've been playing with the idea of using a trigger to manipulate SV_Friction on rough terrain (to slow you down) and icy terrian (slip n' slide), so I'd like to keep that if I can. But if I can get it to affect forward movement only, then I might be able to make some better headway going uphill and downhill. I was thinking something like

if ((self.velocity_z) > 1) {
stuffcmd(self,"sv_friction... lots of friction, you're going uphill so it should be harder and require you to pedal more to go the same distance");
}

if ((self.velocity_z) < 1) {
stuffcmd...etc. You should speed up quite a bit going downhill.

But I need it to affect forward movement only. So if you're turned sideways on a hill or ramp, you actually won't go anywhere. If you face up or downhill, you then start to slide. The way I worked it out above doesn't really address this issue of "facing". I almost need like a trigger_push that pushes you backwards while going uphill and forwards while going downhill.


2. How can I make the player turn without using +left and +right?
The handlebars do the turning, and it is a type of "constant turn". When your handlebars are titled to the left, you continuously turn left. The sharper they are turned, the more heavily you turn in the game. A regular mouse movement would just turn you a certain amount and then stop. I've done this so far by using the prydoncursor and a type of call of duty aiming style. When the cursor position is very close to the center, you don't turn. Move it a little to the left, you continuously turn left slowly. Move it more to the left, you turn a lot. I vary the actual turn speed by stuffing cl_yawspeed proportional to the cursor position.

void () CheckTurn =
{
local string t;

if (!((self.flags) & FL_ONGROUND)) {
return;
}

if ((self.cursor_active) < 1) {
stuffcmd (self, "cl_yawspeed 140\n");
return;
}

t = ftos (200*((self.cursor_screen_x)*(self.cursor_screen_x))); <-- I needed to square the value to make it positive.
stuffcmd (self, "cl_yawspeed ");
stuffcmd (self,t);
stuffcmd (self, "\n");


if ((self.cursor_screen_x) > 0.05) {
stuffcmd (self, "+right\n");
}
else {

if ((self.cursor_screen_x) < -0.05) {
stuffcmd (self, "+left\n");
}
else {
stuffcmd (self, "-left\n");
stuffcmd (self, "-right\n");


This seems to work pretty well, but it's a little buggy and I know it's a backwards way of doing things and I'm sure there's something out there better. Between v_right, v_up, and v_forward I can't seem to figure this out. I need like a v_yaw or something. Any suggestions?

Thanks,
Alex

ps. I'd like to do this all in QC if possible. I'm not really familiar with CSQC or what it really even is.
Nahuel
Posts: 495
Joined: Wed Jan 12, 2011 8:42 pm
Location: mar del plata

Re: SV_Friction/trigger push and Turning

Post by Nahuel »

you can use this for the different velocitys:

stuffcmd(self, "cl_forwardspeed somenumber\n");
stuffcmd(self, "cl_backspeed somenumber\n");
stuffcmd(self, "cl_sidespeed somenumber\n");

maybee you can turn the cl_sidespeed and cl_backspeed to 0 :?, sorry i do not understand many, my english is very bad :(
hi, I am nahuel, I love quake and qc.
DolphinsOfCydonia
Posts: 21
Joined: Tue Nov 08, 2011 4:01 am

Re: SV_Friction/trigger push and Turning

Post by DolphinsOfCydonia »

Darkplaces allows for physics to be calculated from QC - http://icculus.org/twilight/darkplaces/files/sv_user.qc

You could incorporate kinetic friction/drag/rolling resistance as just another force from here. Something like

dragforce = v_forward * self.velocity * dragconstant; ?
Alex
Posts: 24
Joined: Sun Feb 13, 2011 6:24 pm

Re: SV_Friction/trigger push and Turning

Post by Alex »

Great, thanks for the info so far guys. Any idea on how to tell if you're facing uphill or downhill? or on how to make the player turn without using stuffcmd?
DolphinsOfCydonia
Posts: 21
Joined: Tue Nov 08, 2011 4:01 am

Re: SV_Friction/trigger push and Turning

Post by DolphinsOfCydonia »

Well, one way would be to get the normal of the surface the player entity is perched upon? To do this you could use a traceline. Unless there is a better builtin.
Alex
Posts: 24
Joined: Sun Feb 13, 2011 6:24 pm

Re: SV_Friction/trigger push and Turning

Post by Alex »

Ok, so that seems to make sense and I was thinking of that, except I'm not skilled enough to figure out how to do this. Vectors and angles are things I'm just starting to get into. Any more details on how to do this? Sorry, I'm sure nobody wants to baby me, but thanks for your patience.

Alex
Post Reply