Shift camera sideways toward player angle

This commit is contained in:
fickleheart 2019-12-08 15:54:16 -06:00
parent 4784eb68fa
commit e92d7eca8e
5 changed files with 37 additions and 9 deletions

View File

@ -826,6 +826,8 @@ void D_RegisterClientCommands(void)
// hi here's some new controls
CV_RegisterVar(&cv_abilitydirection[0]);
CV_RegisterVar(&cv_abilitydirection[1]);
CV_RegisterVar(&cv_cam_shiftfacing[0]);
CV_RegisterVar(&cv_cam_shiftfacing[1]);
CV_RegisterVar(&cv_cam_turnfacing[0]);
CV_RegisterVar(&cv_cam_turnfacing[1]);
CV_RegisterVar(&cv_cam_turnfacingability[0]);

View File

@ -400,6 +400,10 @@ consvar_t cv_abilitydirection[2] = {
{"abilitydirection2", "Movement", CV_SAVE, directionchar_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL},
};
static CV_PossibleValue_t zerotoone_cons_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0, NULL}};
consvar_t cv_cam_shiftfacing[2] = {
{"cam_shiftfacingchar", "0.33", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL},
{"cam2_shiftfacingchar", "0.33", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL},
};
consvar_t cv_cam_turnfacing[2] = {
{"cam_turnfacingchar", "0.002", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL},
{"cam2_turnfacingchar", "0.002", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL},

View File

@ -77,7 +77,7 @@ extern consvar_t cv_sideaxis2,cv_turnaxis2,cv_moveaxis2,cv_lookaxis2,cv_jumpaxis
extern consvar_t cv_ghost_bestscore, cv_ghost_besttime, cv_ghost_bestrings, cv_ghost_last, cv_ghost_guest;
// hi here's some new controls
extern consvar_t cv_abilitydirection[2], cv_cam_turnfacing[2], cv_cam_turnfacingability[2], cv_cam_turnfacinginput[2];
extern consvar_t cv_abilitydirection[2], cv_cam_shiftfacing[2], cv_cam_turnfacing[2], cv_cam_turnfacingability[2], cv_cam_turnfacinginput[2];
// mouseaiming (looking up/down with the mouse or keyboard)
#define KB_LOOKSPEED (1<<25)

View File

@ -1182,9 +1182,10 @@ static menuitem_t OP_CameraOptionsMenu[] =
{IT_STRING | IT_CVAR | IT_CV_INTEGERSTEP, NULL, "Camera Height", &cv_cam_height, 70},
{IT_STRING | IT_CVAR | IT_CV_FLOATSLIDER, NULL, "Camera Speed", &cv_cam_speed, 80},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to character angle", &cv_cam_turnfacing[0], 100},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to ability", &cv_cam_turnfacingability[0], 110},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to input", &cv_cam_turnfacinginput[0], 120},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Shift to character angle", &cv_cam_shiftfacing[0], 100},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to character angle", &cv_cam_turnfacing[0], 110},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to ability", &cv_cam_turnfacingability[0], 120},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to input", &cv_cam_turnfacinginput[0], 130},
{IT_STRING | IT_CVAR, NULL, "Crosshair", &cv_crosshair, 140},
};
@ -1200,9 +1201,10 @@ static menuitem_t OP_Camera2OptionsMenu[] =
{IT_STRING | IT_CVAR | IT_CV_INTEGERSTEP, NULL, "Camera Height", &cv_cam2_height, 70},
{IT_STRING | IT_CVAR | IT_CV_FLOATSLIDER, NULL, "Camera Speed", &cv_cam2_speed, 80},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to character angle", &cv_cam_turnfacing[1], 100},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to ability", &cv_cam_turnfacingability[1], 110},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to input", &cv_cam_turnfacinginput[1], 120},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Shift to character angle", &cv_cam_shiftfacing[1], 100},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to character angle", &cv_cam_turnfacing[1], 110},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to ability", &cv_cam_turnfacingability[1], 120},
{IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to input", &cv_cam_turnfacinginput[1], 130},
{IT_STRING | IT_CVAR, NULL, "Crosshair", &cv_crosshair2, 140},
};

View File

@ -9677,6 +9677,9 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
subsector_t *newsubsec;
fixed_t f1, f2;
static fixed_t camsideshift[2] = {0, 0};
fixed_t shiftx = 0, shifty = 0;
// We probably shouldn't move the camera if there is no player or player mobj somehow
if (!player || !player->mo)
return true;
@ -9882,6 +9885,20 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
}
}
if (cv_abilitydirection[(thiscam == &camera) ? 0 : 1].value)
{
// Shift the camera slightly to the sides depending on the player facing direction
UINT8 forplayer = (thiscam == &camera) ? 0 : 1;
fixed_t shift = FixedMul(FINESINE((player->drawangle - angle) >> ANGLETOFINESHIFT), cv_cam_shiftfacing[forplayer].value);
shift += FixedMul(camsideshift[forplayer] - shift, FRACUNIT-(camspeed>>3));
camsideshift[forplayer] = shift;
shift = FixedMul(shift, camdist);
shiftx = -FixedMul(FINESINE(angle>>ANGLETOFINESHIFT), shift);
shifty = FixedMul(FINECOSINE(angle>>ANGLETOFINESHIFT), shift);
}
// sets ideal cam pos
if (twodlevel || (mo->flags2 & MF2_TWOD))
dist = 480<<FRACBITS;
@ -10228,8 +10245,8 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
}
else
{
viewpointx = mo->x + FixedMul(FINECOSINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist);
viewpointy = mo->y + FixedMul(FINESINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist);
viewpointx = mo->x + shiftx + FixedMul(FINECOSINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist);
viewpointy = mo->y + shifty + FixedMul(FINESINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist);
}
if (!camstill && !resetcalled && !paused)
@ -10270,6 +10287,9 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall
}
else
thiscam->momz = FixedMul(z - thiscam->z, camspeed);
thiscam->momx += FixedMul(shiftx, camspeed);
thiscam->momy += FixedMul(shifty, camspeed);
}
// compute aming to look the viewed point