Page 1 of 2

custom chasecam tutorial

Posted: Sat Sep 20, 2008 4:33 pm
by frag.machine
This small tutorial is inspired by the excellent ArcadeQuake project shown in the last QExpo. We will add a customizable 3rd. person chasecam, enabled by the original chase_active cvar using the value = 2 (chase_active 1 stills working as usual). I am assuming vanilla GLQuake / WinQuake source code with the almost mandatory chasecam fix tutorial applied as the base code. If you don't want or can't apply this fix, just skip the commented part in the code, although the camera will "see" through the world geometry.

So, let's start opening up the chase.c. At the begin, you will find this:

Code: Select all

cvar_t  chase_back = {"chase_back", "100"};
cvar_t  chase_up = {"chase_up", "16"};
cvar_t  chase_right = {"chase_right", "0"};
cvar_t  chase_active = {"chase_active", "0"};
After it, add these new cvars:

Code: Select all

cvar_t  chase_roll = {"chase_roll", "0"};
cvar_t  chase_yaw = {"chase_yaw", "180"};
cvar_t  chase_pitch = {"chase_pitch", "45"};
These will control the fixed angles of our camera. The default values are set to show the player in the same angle as in a side-scroller game.

Below, we have the Chase_Init () function. We paste this at the end of the code:

Code: Select all

    Cvar_RegisterVariable (&chase_roll);
    Cvar_RegisterVariable (&chase_yaw);
    Cvar_RegisterVariable (&chase_pitch);
Now we can access our new cvars by console.

Finally, we will replace the original Chase_Update function with this:

Code: Select all

void Chase_Update (void)
{
    int     i;
    float   dist;
    vec3_t  forward, up, right;
    vec3_t  dest, stop;

    if ((int)chase_active.value != 2)
    {
        // if can't see player, reset
        AngleVectors (cl.viewangles, forward, right, up);

        // calc exact destination
        for (i=0 ; i<3 ; i++)
            chase_dest[i] = r_refdef.vieworg[i] 
            - forward[i]*chase_back.value
            - right[i]*chase_right.value;
        chase_dest[2] = r_refdef.vieworg[2] + chase_up.value;

        // find the spot the player is looking at
        VectorMA (r_refdef.vieworg, 4096, forward, dest);
        TraceLine (r_refdef.vieworg, dest, stop);

        // calculate pitch to look at the same spot from camera
        VectorSubtract (stop, r_refdef.vieworg, stop);
        dist = DotProduct (stop, forward);
        if (dist < 1)
            dist = 1;

        r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180;

            TraceLine(r_refdef.vieworg, chase_dest, stop);
        if (Length(stop) != 0)
            VectorCopy(stop, chase_dest);

        // move towards destination
        VectorCopy (chase_dest, r_refdef.vieworg);
    }
    else
    {
        chase_dest[0] = r_refdef.vieworg[0] + chase_back.value;
        chase_dest[1] = r_refdef.vieworg[1] + chase_right.value;
        chase_dest[2] = r_refdef.vieworg[2] + chase_up.value;

        // this is from the chasecam fix - start
        TraceLine (r_refdef.vieworg, chase_dest, stop);      
        if (Length (stop) != 0)
        {
            VectorCopy (stop, chase_dest);
        }
        // this is from the chasecam fix - end

        VectorCopy (chase_dest, r_refdef.vieworg);
        r_refdef.viewangles[ROLL] = chase_roll.value;
        r_refdef.viewangles[YAW] = chase_yaw.value;
        r_refdef.viewangles[PITCH] = chase_pitch.value;
    }
}
And that's it. Compile the code, start a new single player game, bring down the console and experiment with the cvars values, like this:

Code: Select all

chase_active 2
chase_up 64
chase_pitch 45
chase_back 200

Posted: Sun Nov 30, 2008 4:42 pm
by MeTcHsteekle
hehe this one is fun :D

Posted: Thu Jun 10, 2010 4:42 am
by Baker
The following settings are one of many sets that work very well ...

(some RPGs use this type of angle)

chase_right -160
chase_back -160
chase_up 200
chase_roll 0
chase_pitch 45
chase_yaw 45

Of course, these work well too ...

(overhead)

chase_right 0
chase_back 0
chase_up 200
chase_roll 0
chase_pitch 90
chase_yaw 0

Secretly this has been of the simplest and most useful tutorials ever. Especially combined with MH and R00k's super-enhanced chasecam fixes.

Posted: Thu Jun 10, 2010 5:19 pm
by ceriux
omg i wish i was home -.- i want to start my orpg so bad! hopefully only two months left.

Posted: Thu Aug 19, 2010 4:22 am
by jonyroger
These is one of the great information. Go GLQuake vanilla / source WinQuake almost mandatory chasecam confirm tutorial applies to the code base. If you do not want or can not apply this fix, jump into the comment part of the code, although the camera to see through the world geometry.

Posted: Sat Sep 04, 2010 10:03 pm
by dreadlorde
Interesting. It would be cool to see if someone could do something with this in MP. I love third person matches in CoD:MW2 (the only way I can play CoD anymore :p), and it would be cool to see if it could work well in Quake. It might be weird because it the player in quake doesn't actually have a body, but that seems like an easy fix.

Posted: Sun Sep 05, 2010 2:10 am
by Sajt
IIRC getting the player model to show up was a trivial fix in the engine code. Search for "// don't draw the player" in r_main.c and add a chase_active cvar check to that if condition...

Posted: Thu Sep 30, 2010 10:12 pm
by hondobondo
ok i tried this and everything looks real good

Image

but the camera orientation doesn't change with the mouse. it makes it a bit of an effort to play. the player spins around, but i would rather the camera spin, so left is still left and so on. any ideas?

Posted: Thu Sep 30, 2010 11:46 pm
by frag.machine
comment the following line in the tutorial:

Code: Select all

r_refdef.viewangles[YAW] = chase_yaw.value; 

Posted: Fri Oct 01, 2010 1:54 am
by hondobondo
frag.machine wrote:comment the following line in the tutorial:

Code: Select all

r_refdef.viewangles[YAW] = chase_yaw.value; 
pardon my french but that is a F*CKLOAD of awesome. thanks frag. look for more on that soon

Posted: Mon Oct 04, 2010 1:42 pm
by Mexicouger
DELETED. Fixed Problem

Posted: Mon Oct 04, 2010 2:10 pm
by frag.machine
Mexicouger wrote:How Would I make it so the game think I am looking straight forward(For an overhead camera)

It would be really nice. Right now, The player is looking straight down into the ground(And the model is like on his belly on the ground)

Thanks
Just disable mouselook. :)

Posted: Mon Oct 04, 2010 2:17 pm
by frag.machine
hondobondo wrote:
frag.machine wrote:comment the following line in the tutorial:

Code: Select all

r_refdef.viewangles[YAW] = chase_yaw.value; 
pardon my french but that is a F*CKLOAD of awesome. thanks frag. look for more on that soon
LOL, Contra Quake anyone ?

Posted: Mon Oct 04, 2010 4:53 pm
by hondobondo
frag.machine wrote:
hondobondo wrote:
frag.machine wrote:comment the following line in the tutorial:

Code: Select all

r_refdef.viewangles[YAW] = chase_yaw.value; 
pardon my french but that is a F*CKLOAD of awesome. thanks frag. look for more on that soon
LOL, Contra Quake anyone ?
IKARI WARRIORS?

Posted: Mon Oct 04, 2010 7:58 pm
by gnounc
JACKAL?!?!?! oh wait that ones been done.