custom chasecam tutorial

Post tutorials on how to do certain tasks within game or engine code here.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

custom chasecam tutorial

Post 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
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
MeTcHsteekle
Posts: 399
Joined: Thu May 15, 2008 10:46 pm
Location: its a secret

Post by MeTcHsteekle »

hehe this one is fun :D
bah
Baker
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Post 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.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
ceriux
Posts: 2230
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Post by ceriux »

omg i wish i was home -.- i want to start my orpg so bad! hopefully only two months left.
jonyroger
Posts: 3
Joined: Thu Aug 19, 2010 3:53 am

Post 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.
dreadlorde
Posts: 268
Joined: Tue Nov 24, 2009 2:20 am
Contact:

Post 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.
Last edited by dreadlorde on Sun Sep 05, 2010 6:13 am, edited 1 time in total.
Ken Thompson wrote:One of my most productive days was throwing away 1000 lines of code.
Get off my lawn!
Sajt
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Post 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...
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

Post 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?
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post by frag.machine »

comment the following line in the tutorial:

Code: Select all

r_refdef.viewangles[YAW] = chase_yaw.value; 
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

Post 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
Mexicouger
Posts: 514
Joined: Sat May 01, 2010 10:12 pm
Contact:

Post by Mexicouger »

DELETED. Fixed Problem
Last edited by Mexicouger on Tue Oct 05, 2010 3:21 am, edited 1 time in total.
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post 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. :)
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
frag.machine
Posts: 2126
Joined: Sat Nov 25, 2006 1:49 pm

Post 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 ?
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

Post 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?
gnounc
Posts: 428
Joined: Mon Apr 06, 2009 6:26 am

Post by gnounc »

JACKAL?!?!?! oh wait that ones been done.
Post Reply