CSQC Real recoil for Quake
Author: kleskbyUnlike many other games quake has only visual recoil that does not affect player's accuracy. You could notice that after taking a shot your camera receives a punch but always returns to the same angles. In this tutorial we will fix that.
Let's start. First we need to open our CSQC_UpdateView function (if you don't know what is this see previous CSQC tutorials).
Let's add float variable deltaTime. What is that? Delta time is an interval from the last frame to the current one. We need it to achieve fps independent smooth recoil.
float lastFrame;
float deltaTime;
void CSQC_UpdateView(float flWidth, float flHeight)
{
deltaTime = time - lastFrame;
lastFrame = time;
........some code......
}
Now we have our deltaTime. How do we get the recoil and change the player angles from CSQC?
I will calculate on-screen recoil based on view_punchangle (see csprogsdefs.qc). You, however, can register another stat and use getstat() function. Do not forget to add initial view angles (input_angles variable from csprogsdefs).
To change the angles we use setproperty() function with VF_CL_VIEWANGLES parameter.
Let's see the full code:
float lastFrame;
float deltaTime;
void CSQC_UpdateView(float flWidth, float flHeight)
{
clearscene(); // CSQC builtin to clear the scene of all entities / reset our view properties
setproperty(VF_DRAWWORLD, 1); // we want to draw world!
setproperty(VF_DRAWCROSSHAIR, 0); // we want to draw our crosshair!
setproperty(VF_DRAWENGINESBAR, 0);
addentities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS); // add entities with these rendermask field var's to our view
renderscene();
deltaTime = time - lastFrame;
lastFrame = time;
setproperty(VF_CL_VIEWANGLES, input_angles + [ view_punchangle_x * 3 * deltaTime, view_punchangle_y * 3 * deltaTime]); //recoil
}
Tags: quakec, CSQC, quake, DarkPlaces