- {
- // calculate for swinging gun model
- // the gun bobs when running on the ground, but doesn't bob when you're in the air.
- // Sajt: I tried to smooth out the transitions between bob and no bob, which works
- // for the most part, but for some reason when you go through a message trigger or
- // pick up an item or anything like that it will momentarily jolt the gun.
- vector forward, right, up;
- float bspeed;
- float t = 1;
- float s = time * autocvar_cl_bobmodel_speed;
- if (clonground)
- {
- if (time - hitgroundtime < 0.2)
- {
- // just hit the ground, speed the bob back up over the next 0.2 seconds
- t = time - hitgroundtime;
- t = bound(0, t, 0.2);
- t *= 5;
- }
- }
- else
- {
- // recently left the ground, slow the bob down over the next 0.2 seconds
- t = time - lastongroundtime;
- t = 0.2 - bound(0, t, 0.2);
- t *= 5;
- }
- bspeed = xyspeed * 0.01;
- MAKEVECTORS(makevectors, view_angles, forward, right, up);
- float bobr = bspeed * autocvar_cl_bobmodel_side * autocvar_cl_viewmodel_scale * sin(s) * t;
- gunorg += bobr * right;
- float bobu = bspeed * autocvar_cl_bobmodel_up * autocvar_cl_viewmodel_scale * cos(s * 2) * t;
- gunorg += bobu * up;
- }
- vector v = rotate(gunorg, YAW(view_angles) * DEG2RAD); // rotate world coordinates to relative ones
- v.z = gunorg.z;
- this.origin += v;
- gunangles.x = -gunangles.x; // pitch was inverted, now that actually matters
- this.angles += gunangles;